Escape The Maze (easy version) solution codeforces
The only difference with E2 is the question of the problem..
Vlad built a maze out ofrooms and bidirectional corridors. From any room any other room can be reached through a sequence of corridors. Thus, the room system forms an undirected tree.
Vlad invitedfriends to play a game with them.
Vlad starts the game in the roomand wins if he reaches a room other than , into which exactly one corridor leads. Escape The Maze (easy version) solution codeforces
Friends are placed in the maze: the friend with numberis in the room , and no two friends are in the same room (that is, for all ). Friends win if one of them meets Vlad in any room or corridor before he wins.
For one unit of time, each participant of the game can go through one corridor. All participants move at the same time. Participants may not move. Each room can fit all participants at the same time.
Friends know the plan of a maze and intend to win. Vlad is a bit afraid of their ardor. Determine if he can guarantee victory (i.e. can he win in any way friends play).
In other words, determine if there is such a sequence of Vlad’s moves that lets Vlad win in any way friends play.
The first line of the input contains an integer( ) — the number of test cases in the input. The input contains an empty string before each test case.
The first line of the test case contains two numbersand ( ) — the number of rooms and friends, respectively.
The next line of the test case containsintegers ( ) — numbers of rooms with friends. All are different.
The nextlines contain descriptions of the corridors, two numbers per line and ( ) — numbers of rooms that connect the corridor. All corridors are bidirectional. From any room, you can go to any other by moving along the corridors.
It is guaranteed that the sum of the valuesover all test cases in the test is not greater than .
Print YES” if Vlad can guarantee himself a victory and “NO” otherwise.lines, each line containing the answer to the corresponding test case. The answer to a test case should be “
You may print every letter in any case you want (so, for example, the strings “yEs“, “yes“, “Yes” and “YES” will all be recognized as positive answers).
4 8 2 5 3 4 7 2 5 1 6 3 6 7 2 1 7 6 8 3 1 2 1 2 2 3 3 1 2 1 2 1 3 3 2 2 3 3 1 1 2
Escape The Maze (easy version) solution codeforces output
YES NO YES NO
In the first test case, regardless of the strategy of his friends, Vlad can win by going to room. The game may look like this: