|시간 제한||메모리 제한||제출||정답||맞은 사람||정답 비율|
|2 초||256 MB||5||5||5||100.000%|
While you weren't watching, your N robots have developed a life of their own and spread throughout your hometown. Each of your hometown's N intersections (numbered 0,…,N-1) contains exactly one robot. On each intersection i, there is exactly one red signpost pointing to an intersection, ri ≠ i, and exactly one green signpost pointing to an intersection gi ≠ i. When you press the red button on your remote control, each robot will move to the intersection indicated by the red signpost (robots at intersection i move to ri). When you press the green button, each robot will move to the intersection indicated by the green signpost (robots at intersection i move to gi). Write a program that determines whether you can make the robots all meet at the same intersection at the same time via some sequence of commands on your remote control.
The first line of input contains a single decimal integer P, (1 ≤ P ≤ 500), which is the number of data sets that follow. Each data set should be processed identically and independently.
Each data set consists three lines of input as follows:
On some intersections, both signposts might point the same way (i.e. ri = gi).
For each data set there is one line of output. The single output line consists of the string “YES” if you can make all robots meet or “NO” otherwise.
2 1 4 1 2 3 0 3 0 1 0 2 4 1 2 3 0 2 2 1 2
1 NO 2 YES
Note: For the second case, the button press sequence GREEN, RED, RED, GREEN makes all robots meet at intersection 2.