Hanyang Cherry Picking Contest
Time limit1sMemory limit1024 MB
Two players alternately take tree vertices by moving to a child of the last taken vertex, and the task is to find the winner under optimal play.
- Level
Hard8 of 10
- Topics
- Tree, Game theory, Dynamic programming
- Solved
- No attempts yet
Problem
Sehun and Cheolmin took part in the 10th HCPC (Hanyang Cherry Picking Contest). The two met in the final and compete for the title. The rules of HCPC are as follows.
- A tree with vertices is given, rooted at vertex . Each vertex has an integer between and , inclusive.
- Each match is played between two players. One player moves first and the other moves second.
- A player gains the score of a vertex by taking that vertex. The score of a vertex is the number written on it.
- The vertex most recently taken by the player of the previous turn is called the cherry vertex.
- On the first turn, the first player always takes the root and passes the turn to the second player. The initial cherry vertex is therefore the root.
- After that, the players take turns. On each turn, the player picks one child of the cherry vertex, takes it, and passes the turn.
- A vertex already taken by either player cannot be taken again by either player.
- If the cherry vertex has exactly one child, the player must take that child.
- If the cherry vertex has no children, the nearest vertex that still has a child available is treated as the cherry vertex, and the turn proceeds.
- The match continues until no vertex can be taken. The player whose taken vertices have the higher total score wins. If the totals are equal, the match is a draw.
Sehun moves first and Cheolmin moves second. If both players play optimally, who is the winner of HCPC?
Input
The first line contains .
From the second line onward, the next lines each contain two integers and , separated by a space. They describe an undirected edge between vertex and vertex .
The -th line contains integers . is the number written on vertex .
Output
If Sehun wins, print Sehun. If Cheolmin wins, print Cheolmin. If the match is a draw, print Draw.