JOI-kun이 각 명소의 게시판에 0 또는 1을 적어 X를 전달하고, IOI-chan은 시작 위치 P에서 이동하며 읽은 값으로 X를 알아내는 두 프로그램을 설계한다.
어려움9그래프DFS구현아직 제출이 없습니다시간 제한2초메모리 제한512 MBJOI-kun has a younger sister, IOI-chan. JOI-kun is now playing with IOI-chan in an amusement park called JOIOI park.
There are N attractions in JOIOI park numbered from 0 to N−1. Also, there are M paths in JOIOI park. We can walk each path in both directions. Each path connects two distinct attractions. We can move from any attraction to any other attractions by passing through one or more paths. Because JOI-kun and IOI-chan have the map of JOIOI park, they know how attractions are connected by paths.
Each attraction has a message board. On each message board, JOI-kun can write only one integer, either 0 or 1. He can write different integers on different message boards. Once he writes an integer on a message board, it will not be overwritten by other visitors.
JOI-kun and IOI-chan want to play with different attractions. Therefore, they will play separately for a while, and then, they will meet at some point. Since they do not have communication tools such as mobile phones, JOI-kun decided to use message boards to tell an integer X, which describes a time to meet, to IOI-chan.
In concrete terms, JOI-kun and IOI-chan will communicate by the following way:
By small number of moves, IOI-chan wants to know the integer X which JOI-kun wants to tell.
Write two programs which enable for JOI-kun to tell the integer X to IOI-chan.
Note that two programs will be given exactly the same information about the paths in JOIOI park. In particular, the numbers representing the attractions given to the two programs are the same. Also, the orders of the paths given to the two programs are the same.
All input data satisfy the following conditions. See section of ‘Input for the sample grader’ for the meaning of the variables N, M, A[i], B[i], P, X.
A[i] ≤ N − 1 (0 ≤ i ≤ M − 1).B[i] ≤ N − 1 (0 ≤ i ≤ M − 1).A[i] ≠ B[i] (0 ≤ i ≤ M − 1).A[i], B[i]) ≠ (A[j], B[j]) (0 ≤ i < j ≤ M − 1).A[i], B[i]) ≠ (B[j], A[j]) (0 ≤ i < j ≤ M − 1).