比赛 20091102 评测结果 AAWWW
题目名称 复原几何图形 最终得分 40
用户昵称 rottenwood 运行时间 0.000 s
代码语言 Pascal 内存使用 0.00 MiB
提交时间 2009-11-02 11:31:53
显示代码纯文本
program resume;
var
map:array[1..50,1..50] of boolean;
f:array[1..50] of boolean;
ans:array[1..3000,1..50] of integer;
s:array[1..50] of integer;
flag:array[1..3000] of boolean;
i,j,k,m,n,min,tol,c,ans1,x,y:longint;
procedure sort;
var i,j:longint;

 begin
 fillchar(flag,sizeof(flag),true);
  for i:=1 to n do
  begin
  min:=maxint;
   for j:=1 to tol do
   begin
   if (ans[j,i]<min)and(flag[j]) then min:=ans[j,i];
   for k:=1 to tol do if (ans[k,i]>min)and(flag[k]) then flag[k]:=false;
   end;
 end;
end;
procedure print;
var i,j:longint;
begin
inc(tol);
for i:=1 to n do ans[tol,i]:=s[i];
end;

procedure search(x:integer);
var i,j:longint;
begin
if c=n then begin print; exit; end;
 for i:=1 to n do
  if (map[x,i])and(not f[i]) then
   begin
    f[i]:=true;
    inc(c); s[c]:=i;
    search(i);
    f[i]:=false;
    dec(c);
    end;
end;
begin
assign(input,'resume.in');reset(input);
assign(output,'resume.out');rewrite(output);
readln(n);
for i:=1 to n do
begin
readln(x,y);
map[x,y]:=true;
map[y,x]:=true;
end;
for i:=1 to n do
begin
search(i);
end;
sort;
for i:=1 to tol do if flag[i] then ans1:=i;
for i:=1 to n-1 do
write(ans[ans1,i],' ');
writeln(ans[ans1,n]);
close(output);
end.