Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
pascal 水代码Program poj3687; Var n,m,tot,t:longint; ru:array[0..201] of longint; pre,son:array[0..50002] of longint; now,ans:array[0..201] of longint; use:array[0..201] of boolean; Procedure build(a,b:longint); begin inc(tot); pre[tot]:=now[a]; now[a]:=tot; son[tot]:=b; end; Procedure init; var i,j,a,b:longint; begin readln(n,m); fillchar(ru,sizeof(ru),0); fillchar(now,sizeof(now),0); fillchar(use,sizeof(use),false); for i:=1 to m do begin readln(a,b); inc(ru[a]); build(b,a); end; end; Procedure work; var i,j,p,sum:longint; begin sum:=0; for i:=n downto 1 do begin for j:=n downto 1 do if (ru[j]=0) and (not use[j]) then begin ans[j]:=i; inc(sum); use[j]:=true; p:=now[j]; while p<>0 do begin dec(ru[son[p]]); p:=pre[p]; end; break; end; end; if sum <> n then begin writeln(-1); exit; end; for i:=1 to n do write(ans[i],' '); writeln; end; Procedure print; var i:longint; begin readln(t); for i:=1 to t do begin init; work; end; end; Begin print; readln; readln; End. Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator