输出描述 Output Description
输出应当有F+1行,每行一个整数,依次表示路径经过的顶点号。注意数据可能有多组解,但是只有上面题目要求的那一组解是认为正确的。 样例输入 Sample Input 9 1 2 2 3 3 4 4 2 4 5 2 5 5 6 5 7 4 6 样例输出 Sample Output 1 2 3 4 2 5 4 6 57
代码:
var a:array[0..2000]of longint; d:array[0..500]of longint; e,v:array[0..500,0..500]of longint; x,y,i,f,n,s1:longint; procedure dfs(t:longint); var s2,j:longint; begin for j:=1 to 500 do if (e[t,j]=1)and(v[t,j]>0) then begin dec(v[j,t]); dec(v[t,j]); dfs(j); end; inc(f); a[f]:=t; end; procedure init; var k:longint; begin readln(n); s1:=maxlongint; for i:=1 to n do begin readln(x,y); if x<s1 then s1:=x; if y<s1 then s1:=y; e[x,y]:=1; e[y,x]:=1; d[x]:=d[x]+1; d[y]:=d[y]+1; v[x,y]:=v[x,y]+1; v[y,x]:=v[y,x]+1; end; end; procedure main; begin for i:=1 to 500 do if d[i] mod 2=1 then begin s1:=i; break; end; dfs(s1); end; procedure print; begin for i:=f downto 1 do writeln(a[i]); end; begin init; main; print; end.
