1 var 2 n,m,i,j,k1,k2:longint; 3 a:array[1..20,1..20] of longint; 4 b:array[1..20] of longint; 5 visited:array[1..20] of boolean; 6 flag:boolean; 7 procedure print(k:longint); 8 var i:longint; 9 begin 10 if k=0 then writeln(‘no round‘) 11 else 12 begin 13 for i:=1 to n-1 do write(b[i],‘ ‘); 14 writeln(b[n]); 15 end; 16 // halt; 17 end; 18 procedure dfs(i,k:longint); 19 var j:longint; 20 begin 21 if k=n then begin print(1); flag:=true; end; 22 for j:=1 to n do 23 if (a[j,i]=1) and (visited[j]=false) then 24 begin 25 visited[j]:=true; 26 b[k+1]:=j; 27 dfs(j,k+1); 28 visited[j]:=false; 29 end; 30 end; 31 begin 32 readln(n,m); 33 fillchar(a,sizeof(a),0); 34 for i:=1 to m do 35 begin 36 readln(k1,k2); 37 a[k1,k2]:=1; 38 a[k2,k1]:=1; 39 end; 40 for i:=1 to n do 41 begin 42 fillchar(visited,sizeof(visited),false); 43 b[1]:=i; 44 visited[i]:=true; 45 dfs(i,1); 46 end; 47 if not(flag) then print(0); 48 end.
时间: 2024-10-28 10:49:46