#Lutece0686. Hero Saving Princess
Hero Saving Princess
Migrated from Lutece 686 Hero Saving Princess
All parts of this problem, including description, images, samples, data and checker, might be broken. If you find bugs in this problem, please contact the admins.
Description
Lovely Senior Sister(xuejie) is captured by evil monsters. Our hero is trying to save her.
The monsters' castle consists of rooms, some rooms have locked doors, some rooms have a key, and some rooms can be passed without difficulty. For each locked door, there's only one key to open it. No keys can open more than one door, no any two keys are in the same room.
Rooms are connected by corridors. The keys are stored inside the room, so if you want to get the key, you have to unlock the room if needed.
Now our hero is at room , it is not locked. He wonders whether he can visit all the rooms in the castle since the position of the xuejie is unknown.
Input
The first line of input contains a number (), indicating the number of test cases.
For each case, there are two numbers and which is the number of rooms and corridors(,). Then lines follow, each with two integers and , indicating there is a corridor between room and room ().
After that, a number is given(). It is the number of locked rooms. At the next lines, each line contains two integers: and , which means there is a key at room which can open the door of room .
Output
For each case, output Case #i:
first. ( is the number of the test case, from to ). Then output the Yes
, or No
, whether the hero can visited all the rooms of the castle, starting with room .
Samples
2
2 1
0 1
0
3 2
0 1
1 2
1
1 2
Case #1: Yes
Case #2: No
Resources
11th UESTC Programming Contest Preliminary