讨论 / 水题 AC pascal
潘崇明 2016-02-18 17:00:31
点我顶贴 收藏 删除
var a,b,c:array[1..1000000] of longint;

n,i,j,x,y,s1,s2:longint;

begin

readln(n);

for i:=1 to n-1 do

begin

readln(x,y);

a[y]:=x;

end;

readln(x,y);

b[1]:=x;

s1:=1;

while x<>0 do

begin

s1:=s1+1;

b[s1]:=a[x];

x:=a[x];

end;

c[1]:=y;

s2:=1;

while y<>0 do

begin

s2:=s2+1;

c[s2]:=a[y];

y:=a[y];

end;

if s1<s2

then begin

for i:=1 to s1 do

for j:=1 to s2 do

if b[i]=c[j]

then begin

writeln(b[i]);

halt;

end;

end

else begin

for i:=1 to s2 do

for j:=1 to s1 do

if c[i]=b[j]

then begin

writeln(c[i]);

halt;

end;

end;

end.

查看更多回复
提交回复