Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register
欢迎参加IJCAI 2020麻将智能体竞赛,大奖等你拿!Welcome to IJCAI 2020 Mahjong AI competition with amazing prizes! | 北京大学《ACM/ICPC大学生程序设计竞赛训练》暑期课面向全球招生!

水过。。。贴个代码。。

Posted by 597100700 at 2011-09-03 22:29:57 on Problem 2457
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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator