比赛 20091102 评测结果 AAWTT
题目名称 复原几何图形 最终得分 40
用户昵称 lc 运行时间 0.000 s
代码语言 Pascal 内存使用 0.00 MiB
提交时间 2009-11-02 11:00:47
显示代码纯文本
program resume;
 const
   maxn = 50;
 var
   n:           longint;
   l:           array[1..maxn,0..maxn] of longint;
   used:        array[1..maxn] of boolean;
   pos,a:       array[1..maxn] of longint;


procedure init;
 var
   i,x,y:   longint;
 begin
   readln(n);
   for i :=1 to n do begin
       readln(x,y);
       inc(l[x][0]); l[x][l[x][0]] :=y;
       inc(l[y][0]); l[y][l[y][0]] :=x;
       end;
 end;


function Check(k,x:longint):boolean;
 var
   i,v,j,u,p,r:   longint;
 begin
   for i :=1 to l[x][0] do begin
       v :=l[x][i];
       if used[v] then
          for j :=pos[v]+1 to k-1 do
              begin
                u :=a[j];
                for r :=1 to l[u][0] do begin
                    p :=l[u][r];
                    if (used[p]) and (pos[p]<pos[v])
                    or (not used[p]) and (p <>x) then exit(false);
                    end;
              end;
       end;
   exit(true);
 end;

procedure print;
 var
   i:   longint;
 begin
   for i :=1 to n-1 do write(a[i],' ');
   writeln(a[n]);
   close(input);  close(output); halt;
 end;


procedure solve(k:longint);
 var
   i:   longint;
 begin
   if k >n then print;
   for i :=1 to n do if not used[i]
       then if Check(k,i)
       then begin
            used[i] :=true;
            pos[i] :=k;
            a[k] :=i;
            solve(k+1);
            used[i] :=false;
            pos[i] :=0;
            a[k] :=0;
            end;
 end;




procedure main;

 begin
   solve(1);
 end;





begin
  assign(input,'resume.in');  reset(input);
  assign(output,'resume.out'); rewrite(output);
  init;
  main;
  close(input);  close(output);
end.