#629
Unrated
Custodial Cleanup
시간 제한
2s
메모리 제한
1024MB
제출
0
정답
0
맞힌 사람
0
정답 비율
0.0%

문제

Due to the disorganized structure of his mootels (much like motels but with bovine rather than human guests), Farmer John has decided to take up the role of the mootel custodian to restore order to the stalls.

Each mootel has NN stalls labeled 11 through NN (1N1051 \le N \le 10^5) and MM (0M1050 \le M \le 10^5) corridors that connect pairs of stalls to each other bidirectionally. The iith stall is painted with color CiC_i and initially has a single key of color SiS_i in it. FJ will have to rearrange the keys to appease the cows and restore order to the stalls.

FJ starts out in stall 11 without holding any keys and is allowed to repeatedly do one of the following moves: Pick up a key in the stall he is currently in. FJ can hold multiple keys at a time. Place down a key he is holding into the stall he is currently in. A stall may hold multiple keys at a time. Enter stall 11 by moving through a corridor. Enter a stall other than stall 11 by moving through a corridor. He can only do this if he currently holds a key that is the same color as the stall he is entering.

Unfortunately, it seems that the keys are not in their intended locations. To restore order to FJ's mootel, the iith stall requires that a single key of color FiF_i is in it. It is guaranteed that SS is a permutation of FF.

For TT different mootels (1T1001 \le T \le 100), FJ starts in stall 11 and needs to place every key in its appropriate location, ending back in stall 11. For each of the TT mootels, please answer if it is possible to do this.

입력

The first line contains TT, the number of mootels (test cases).

Each test case will be preceded by a blank line. Then, the first line of each test case contains two integers NN and MM.

The second line of each test case contains NN integers. The ii-th integer on this line, CiC_i, means that stall ii has color CiC_i (1CiN1 \le C_i \le N).

The third line of each test case contains NN integers. The ii-th integer on this line, SiS_i, means that stall ii initially holds a key of color SiS_i (1SiN1 \le S_i \le N).

The fourth line of each test case contains NN integers. The ii-th integer on this line, FiF_i, means that stall ii needs to have a key of color FiF_i in it (1FiN1 \le F_i \le N).

The next MM lines of each test case follow. The ii-th of these lines contains two distinct integers, uiu_i and viv_i (1ui,viN1 \le u_i, v_i \le N). This represents that a corridor exists between stalls uiu_i and viv_i. No corridors are repeated.

The sum of NN over all mootels will not exceed 10510^5, and the sum of MM over all mootels will not exceed 21052\cdot 10^5.

출력

For each mootel, output YES on a new line if there exists a way for FJ to return a key of color FiF_i to each stall ii and end back in stall 11. Otherwise, output NO on a new line.

예제 입력 1

2

5 5
4 3 2 4 3
3 4 3 4 2
2 3 4 4 3
1 2
2 3
3 1
4 1
4 5

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

예제 출력 1

YES
NO

예제 입력 2

5

2 0
1 2
2 2
2 2

2 1
1 1
2 1
2 1
1 2

2 1
1 1
2 1
1 2
1 2

2 1
1 1
1 2
2 1
1 2

5 4
1 2 3 4 4
2 3 5 4 2
5 3 2 4 2
1 2
1 3
1 4
4 5

예제 출력 2

YES
YES
NO
YES
NO

점수

Test cases 3-6 satisfy N,M8N,M\le 8.Test cases 7-10 satisfy Ci=FiC_i=F_i.Test cases 11-18 satisfy no additional constraints.

코드 제출

코드를 제출하려면 로그인이 필요합니다.

로그인
내 제출
제출 내역이 없습니다.
맞은 사람
아직 맞은 사람이 없습니다.
난이도 투표
Unrated0명 투표
로그인 후 AC 받으면 투표할 수 있습니다.
전체 제출
제출 내역이 없습니다.