Logo
(追記) (追記ここまで)

11527번 - Robots 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
2 초 256 MB49131127.500%

문제

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:

  • The first line contains the data set number, K, followed by a single integer N which is the number of intersections.
  • The second line contains N space separated integers r0, …, rN-1 (0 ≤ ri ≤ N-1 and ri ≠ i).
  • The third line contains N space separated integers g0, …, gN-1 (0 ≤ gi ≤ N-1 and gi ≠ i).

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.

제한

예제 입력 1

2
1 4
1 2 3 0
3 0 1 0
2 4
1 2 3 0
2 2 1 2

예제 출력 1

1 NO
2 YES

힌트

Note: For the second case, the button press sequence GREEN, RED, RED, GREEN makes all robots meet at intersection 2.

출처

ICPC > Regionals > North America > Greater New York Region > 2015 Greater New York Programming Contest F번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /