#P11017. Drifty's Hide and Seek
Drifty's Hide and Seek
Drifty's Hide and Seek
In this problem, two players, hgcnxn and Drifty, play a game of hide and seek on a connected tree. The map is a tree with ( n ) rooms (nodes) and ( n-1 ) corridors (edges) such that there is a unique simple path between any two rooms. hgcnxn starts in room ( p ) and Drifty in room ( q ). The game is played in rounds. In each round, hgcnxn moves first and must move to an adjacent room along one corridor, whereas Drifty moves afterwards and can choose either to stay in his current room or move to an adjacent room. Before the game starts, hgcnxn is allowed to pre-commit to a complete plan of moves (i.e. his movement sequence for all rounds). He designs what he believes is an optimal plan to eventually catch Drifty. However, Drifty is cunning: he knows hgcnxn’s entire plan in advance and will choose his moves optimally with the sole objective of avoiding being caught. The catch occurs the moment hgcnxn enters a room where Drifty is currently located (note that if hgcnxn steps into Drifty's room before Drifty makes his move, capture occurs immediately).
It can be shown that for any tree structure and any valid initial positions ( p ) and ( q ), hgcnxn can devise a pre-committed plan that guarantees he will catch Drifty within ( 10^{100} ) rounds. Your task is to determine, given the tree and the numbers ( n ), ( p ), and ( q ), whether it is possible for hgcnxn to catch Drifty within ( 10^{100} ) rounds.
Input and output details are provided below.
inputFormat
The input begins with a line containing three integers ( n ), ( p ), and ( q ) (1 ( \le n \le 10^5 ), 1 ( \le p,q \le n )). Each of the next ( n-1 ) lines contains two integers ( u ) and ( v ) (1 ( \le u,v \le n )) indicating that there is a corridor connecting rooms ( u ) and ( v ). It is guaranteed that the corridors form a tree.
outputFormat
Output a single line containing “Yes” if hgcnxn can catch Drifty within ( 10^{100} ) rounds following an optimal pre-planned strategy, or “No” otherwise.
sample
2 1 2
1 2
Yes
</p>