아직 만들고 있는 페이지입니다.

이 페이지는 아직 만드는 중입니다. 보이는 내용은 바뀔 수 있습니다.

Power Station of Art

시간 제한3초메모리 제한512 MB

요약
하나의 무방향 그래프와 두 개의 숫자·색 배치가 주어질 때, 간선 양 끝의 숫자를 바꾸고 같은 색이면 두 색을 뒤집는 연산으로 두 배치를 같게 만들 수 있는지 판정한다.
난이도

보통10점 중 7점

유형
그래프, 유니온 파인드, 조합론, 구현
정답자
아직 제출이 없습니다

문제

As a modern art lover, Nocriz loves going to the Power Station of Art.

Currently, art pieces of a modern genre of art called "red-black graphs" are exhibited in the Power Station of Art. Every red-black graph art piece is an undirected labeled graph with numbers and colors associated with each vertex. Each vertex is either red or black.

It is possible to modify a graph in the following way: choose an edge and swap the numbers written on the corresponding vertices. In addition, if the colors of the two vertices are the same, the colors of both vertices are changed (from red to black or from black to red). Otherwise, the colors of the two vertices remain unchanged.

Now, Nocriz is studying two art pieces. The graphs are the same but the numbers and colors may be different. Is it possible to make some (possibly zero) modifications to the art pieces to make them be the same?

입력

The first line contains an integer TT (1≤T≤3⋅1041 \le T \le 3 \cdot 10^4), the number of test cases. Then TT test cases follow.

The first line of each test case contains two integers nn and mm (1≤n≤1061 \le n \le 10^6, 0≤m≤1060 \le m \le 10^6), the number of vertices and edges.

Then mm lines follow, each of them contains two integers u_iu\_i and v_iv\_i (1≤u_i,v_i≤n1 \leq u\_i, v\_i \leq n, u_i≠v_iu\_i \ne v\_i) representing an edge. It is guaranteed that there are no multiple edges in the input, and the graph may be unconnected.

Then numbers and colors of the two graphs follow. For each graph:

The first line contains nn integers, the ii-th integer a_ia\_i (0≤a_i≤1060 \le a\_i \le 10^6) representing the number written on the ii-th vertex of the graph.

The second line contains nn characters. If the ii-th character is 'R', the ii-th vertex is red. If the ii-th character is 'B', the ii-th vertex is black.

It is guaranteed that ∑n≤106\sum n \le 10^6 and ∑m≤106\sum m \le 10^6.

출력

For each test case, output a single line containing "YES" if it is possible to make some (possibly zero) modifications to the art pieces to make them be the same, or "NO" otherwise.

예제1

  1. 예제 1

    입력
    3
    2 1
    1 2
    3 4
    RR
    4 3
    BB
    3 2
    1 2
    2 3
    1 1 1
    RBR
    1 1 1
    BBB
    3 3
    1 2
    2 3
    3 1
    1 1 1
    RBR
    1 1 1
    BBB
    
    예상 출력
    YES
    NO
    YES