One day, you woke up in a huge maze. You did not remember why you are here, but you do remember that you have an important exam this morning! Thus you would like to get out of this maze as soon as possible. You found a map of this maze on the wall, but unfortunately the map did not show where you are. You have to mark yourself on the map first.
According to the map, this maze is formed by rooms and passages. Each passage connects two rooms, and does not intersect with other passages. These passages may form cycles. Each passage belongs to at most 1 cycle, and each room belongs to at most 2 cycles. Also, a room is connected by no more than 2+k passages where k is the number of cycles that this room belongs to. Further more, the i-th cycle may have a common point with ai cycles and there are bi passages which do not belong to any cycle but connect to exactly 1 room in this cycle. ai + bi <= 2.
You walked around for a while, starting from a room and ending in another room. During your walk, you drew a local map of the rooms and passages that you just walked through. You are sure that if a passage on your local map is in a cycle, then all passages in that cycle are also on the local map.
Now, you have the map of whole maze as well as your local map. Can you write a program to determine all the possible locations that you are in?
The first line of input contains an integer T, which is the number of test cases. Any two consecutive test cases are separated by a blank line.
Each test case consists of two map definitions. The former one is the map of the whole maze, and the latter one is the local map. Each map definition begins with two integers, N and M. N and M denote the number of rooms and passages on the map, respectively. Each of the next M lines contains two integers ai and bi, which represent a passage between room ai and room bi.
For each test case, please output 2 lines.
The first line contains a number A, which is the number of possible locations.
The next line contains A numbers in increasing order, which are the possible rooms where your walk ends.
These A numbers are separated by one space.
2 5 5 1 2 2 3 1 3 3 4 4 5 2 1 1 2 7 8 1 2 2 3 3 4 2 4 4 5 4 6 5 6 6 7 4 4 2 3 3 4 2 4 4 1
3 3 4 5 2 2 6
Migrated from old NTUJ.
Ferng
No. | Testdata Range | Score |
---|