|
|
вернуться в форумWhy I got WA? Послано zealot 15 апр 2003 14:35 program airline; const max=50; var map:array[1..max*max,1..2] of longint; cover:array[1..max*max] of boolean; list:array[1..max*max] of longint; n,m:longint; procedure readdata; var i:longint; begin fillchar(map,sizeof(map),0); readln(n,m); for i:=1 to m do readln(map[i][1],map[i][2]); end; procedure print; var i:longint; begin writeln('YES'); for i:=1 to m-1 do write(list[i],' '); writeln(list[m]); halt; end; function zhi(x,p,i:longint):boolean; var j,k,min,t,j1:longint; link:array[1..max*max] of longint; begin fillchar(link,sizeof(link),0); k:=0; min:=maxint; for j:=1 to m do if ((map[j][1]=x)or(map[j][2]=x)) then if (list[j]=0)and(p<>j) then begin zhi:=true; exit; end else if p<>j then begin inc(k); link[k]:=list[j]; if list[j]<min then min:=list[j]; end; inc(k); link[k]:=i; if k=1 then begin zhi:=true; exit; end; for j:=2 to min do begin t:=0; for j1:=1 to k do if link[j1] mod j=0 then inc(t); if t>=k then begin zhi:=false; exit; end; end; zhi:=true; end; procedure search(p:longint); var t,i:longint; begin if p>m then print else begin for i:=1 to n do if not cover[i] then if zhi(map[p][1],p,i) then if zhi(map[p][2],p,i) then begin cover[i]:=true; list[p]:=i; search(p+1); list[p]:=0; cover[i]:=false; end; end; end; procedure main; var i,j:longint; begin fillchar(list,sizeof(list),0); fillchar(cover,sizeof(cover),0); search(1); end; BEGIN readdata; main; writeln('NO'); END. |
|
|