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

福利

Posted by dragondragon at 2015-08-08 17:04:21 on Problem 1330 and last updated at 2015-08-08 17:11:48
var
        a:array[1..10000] of longint;
        i,j,n,t,x,y,k:longint;
        b:array[1..10000] of boolean;
begin
        readln(t);
        for i:=1 to 10000000 do
                inc(t);
        for i:=1 to 10000000 do
                dec(t);
        for i:=1 to t do
        begin
                fillchar(a,sizeof(a),0);
                readln(n);
                for j:=1 to n-1 do
                begin
                        readln(x,y);
                        a[y]:=x;
                end;
                readln(x,y);
                fillchar(b,sizeof(b),false);
                b[x]:=true;
                repeat
                        k:=x;
                        b[k]:=true;
                        x:=a[k];
                until x=0;
                repeat
                        k:=y;
                        if b[k] then
                        begin
                                writeln(k);
                                break;
                        end
                        else
                                b[k]:=true;
                        y:=a[k];
                until y=0;
        end;
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