ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1045. Funny Game

Const
 Max = 10000;
Var
 A: Array [1..Max,0..20] Of Integer;
 Was : Array [1..Max] Of Boolean;
 N,K:Integer;
Procedure DataIn;
 Var
  B,I,J:Integer;
 Begin
{  Assign(InPut,'InPut.txt');
   ReSet(InPut);{}
    FillChar(Was,SizeOf(Was),False);
    ReadLn(N,K);
     For I:=1 To N-1 Do
      Begin
       Read(J,B);
       Inc(A[J,0]);
       A[J,A[J,0]]:=B;
       Inc(A[B,0]);
       A[B,A[B,0]]:=J;
      End;
 End;

Procedure DataOutWin(A:Integer);
  Begin
{  Assign(OutPut,'OutPut.txt');
   ReWrite(OutPut);{}
   Write('First player wins flying to airport ');
   Write(A);
   Halt;
 End;


Procedure DataOutLoose;
 Begin
{  Assign(OutPut,'OutPut.txt');
   ReWrite(OutPut);{}
   WriteLn('First player loses');
   Halt;
 End;

Procedure Work;
Var
 D,I,J,C,C1:Integer;
 List,ExList:Array [1..Max] Of Record
             R:Integer;
             A:Integer;
             End;
 F:Boolean;
 Begin
  C:=1;
  List[1].R:=K;
  Was[K]:=True;
  K:=1;
  D:=0;
  While C<>0 Do
   Begin
    Inc(D);
    C1:=0;
    For I:=1 To C Do
     Begin
      F:=False;
     For J:=1 To A[List[I].R,0] Do
      If Not Was[A[List[I].R,J]] Then
      Begin
       Inc(C1);
       ExList[C1].R:=A[List[I].R,J];
       If D = 1 Then ExList[C1].A:=ExList[C1].R
       Else ExList[C1].A:=List[I].A;
       Was[ExList[C1].R]:=True;
       F:=True;
      End;
      If (Not F) And (K=2) Then DataOutWin(List[i].A);
     End;
     C:=C1;
     List:=ExList;
    K:=3-K;
   End;
 End;

Begin
 DataIn;
  Work;
 DataOutLoose;
End.
"If there are more than one such airports, the program should find
one of them that has the minimal number."

Try this test:
2 1
1 2
1 1
Oscar Is this a valid entry? // Problem 1045. Funny Game 14 Mar 2003 18:43
Isn't it supposed to be N-1 lines refering to the conections between
airports?

If so, then the test case you posted is not a valid one.


> Try this test:
> 2 1
> 1 2
> 1 1