Monthly Advisory Match
Time limit1sMemory limit1024 MB
Given a functional graph with two tokens, decide whether the first or second player wins the vertex-deletion and token-move game, or whether it is a draw.
- Level
Hard10 of 10
- Topics
- Graph, Game theory, DFS
- Solved
- No attempts yet
문제
pjshwa and nadori are playing a game in a field.
The board is a functional graph with vertices. Each player has one token, and each token is on one of the vertices. Several tokens may be on the same vertex.
The two players take turns. On their turn, a player chooses one of the following actions and performs it. A player who cannot make any action on their turn loses.
- Delete vertex and all edges directly connected to . No token may be on vertex .
- Move from the current vertex along its outgoing edge to the neighboring vertex.
To keep the game fair, one player sets up the board and the token positions. The other player checks the board and the token positions, then chooses to go first or second. After that, the game is played. To keep the game from dragging on, if the game is still not over after the second player has made their -th move, the game is a draw.
IBory likes to visit the field and give advice when bored. Today IBory came to give advice as usual, but a game was already in progress. Angry about IBory's advice, nadori prepared a board and waited to play against IBory.
If IBory loses the game, IBory will never be able to give advice again. Can IBory win against nadori, who plays optimally? Help IBory keep giving advice!
입력
The first line contains the number of vertices .
The second line contains the first player's token position and the second player's token position , separated by a space.
The third line contains the sequence , separated by spaces. It means there is a directed edge from vertex to vertex .
출력
Print first if IBory should choose to go first, second if IBory should choose to go second, and draw if every choice leads to a draw.
힌트
A functional graph is a directed graph in which each vertex has exactly one outgoing edge.