F.A.Q
Hand In Hand
Online Acmers
Problem Archive
Realtime Judge Status
Authors Ranklist
 
     C/C++/Java Exams     
ACM Steps
Go to Job
Contest LiveCast
ICPC@China
Best Coder beta
VIP | STD Contests
    DIY | Web-DIY beta
Author ID 
Password 
 Register new ID

Power Station of Art

Time Limit: 5000/5000 MS (Java/Others)    Memory Limit: 524288/524288 K (Java/Others)
Total Submission(s): 268    Accepted Submission(s): 101


Problem Description
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?
 

Input
The first line contains an integer $T (1 \le T \le 30000)$ - the number of test cases. Then $T$ test cases follow.

The first line of each test case contains two integers $n, m (1\le n,m \le 10^6)$ - the number of vertices and edges.

Then $m$ lines follow, each line contains two integers $u_i,v_i(1 \leq u_i, v_i \leq n, u_i \not= v_i)$ representing an edge. It is guaranteed that there are no multiple edges in the input, and the graph $\pmb{\text{may}}$ be unconnected.

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

The first line contains $n$ integers, the $i$-th integer $a_i (0 \le a_i \le 10^6)$ representing the number of the $i$-th node of the graph.

The second line contains $n$ characters. If the $i$-th character is `R', the $i$-th node is red. If the $i$-th character is `B', the $i$-th node is black.

It is guaranteed that $\sum n \le 10^6, \sum m \le 10^6$.
 

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

Sample Input
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
 

Sample Output
YES NO YES
 

Source
 

Statistic | Submit | Discuss | Note
Hangzhou Dianzi University Online Judge 3.0
Copyright © 2005-2024 HDU ACM Team. All Rights Reserved.
Designer & Developer : Wang Rongtao LinLe GaoJie GanLu
Total 0.000000(s) query 1, Server time : 2024-05-12 16:21:43, Gzip enabled