当前你的浏览器版本过低,网站已在兼容模式下运行,兼容模式仅提供最小功能支持,网站样式可能显示不正常。
请尽快升级浏览器以体验网站在线编辑、在线运行等功能。

建议使用的浏览器:

谷歌Chrome 火狐Firefox Opera浏览器 微软Edge浏览器 QQ浏览器 360浏览器 傲游浏览器

7031:Power Station of Art

题目描述
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 $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$.
输出解释
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.
输入样例
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

该题目是Virtual Judge题目,来自 杭电HDUOJ

源链接: HDU-7031

最后修改于 2021-10-23T19:11:07+00:00 由爬虫自动更新

共提交 0

通过率 --%
时间上限 内存上限
5000/5000MS(Java/Others) 524288/524288K(Java/Others)