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 |
水过。。。贴个代码。。var a,b,c,d,e,m,n,sum,l,r:longint; list,next,toit:array[0..1000000]of longint; q,uu,vv,ans:array[0..1000000]of longint; flag:array[0..50000]of boolean; procedure make(i,j:longint); begin inc(sum); toit[sum]:=j; next[sum]:=list[i]; list[i]:=sum; end; begin readln(n,m); sum:=0; for a:=1 to n do begin readln(c,d); make(c,d); end; l:=0;r:=1; q[r]:=1; flag[1]:=true; while l<r do begin inc(l); e:=q[l]; c:=list[e]; while c>0 do begin if not flag[toit[c]] then begin flag[toit[c]]:=true; inc(r); q[r]:=toit[c]; uu[toit[c]]:=l; end; c:=next[c]; end; end; if uu[m]=0 then begin writeln(-1); exit; end; ans[0]:=0; while uu[m]<>0 do begin inc(ans[0]); ans[ans[0]]:=m; m:=q[uu[m]]; end; writeln(ans[0]+1); writeln(1); for a:=ans[0] downto 1 do writeln(ans[a]); end. Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator