IAEPC Preliminary Contest (Codeforces Round 999, Div. 1 + Div. 2)
H1
Kevin and Stones (Easy Version)
Codeforces
3500
原题
← GH2 →
翻译中…

This is the easy version of the problem. The difference between the versions is that in this version, you only need to determine whether a valid sequence of operations exists. You can hack only if you solved all versions of this problem.

翻译中…

Kevin has an undirected graph with $n$ vertices and $m$ edges. Initially, some vertices contain stones, which Kevin wants to move to new positions.

翻译中…

Kevin can perform the following operation:

翻译中…
  • For each stone at $u_i$, select a neighboring vertex $v_i$. Simultaneously move each stone from $u_i$ to its corresponding $v_i$.
翻译中…

At any time, each vertex can contain at most one stone.

翻译中…

Determine whether a valid sequence of operations exists that moves the stones from the initial state to the target state.

翻译中…

Input

翻译中…

Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 1000$). The description of the test cases follows.

翻译中…

The first line of each test case contains two integers $n$ and $m$ ($1\leq n \leq 2000$, $0\leq m \leq \min(\frac{n(n-1)}{2}, 10^4)$) — the number of vertices and edges in the graph.

翻译中…

The second line contains a binary string $s$ consisting of '0' and '1'. The $i$-th bit of $s$ indicates the number of stones on the $i$-th vertex in the initial state.

翻译中…

The third line contains a binary string $t$ consisting of '0' and '1'. The $i$-th bit of $t$ indicates the number of stones on the $i$-th vertex in the target state.

翻译中…

Each of the next $m$ lines contains two integers $u$ and $v$ ($1\leq u, v \leq n$) — an undirected edge between the $u$-th vertex and the $v$-th vertex.

翻译中…

It is guaranteed that the graph is simple. There are no self-loops and parallel edges in the graph.

翻译中…

It is guaranteed that the numbers of '1' in $s$ and $t$ are the same.

翻译中…

It is guaranteed that the sum of $n$ over all test cases does not exceed $2000$.

翻译中…

It is guaranteed that the sum of $m$ over all test cases does not exceed $10^4$.

翻译中…

Output

翻译中…

For each test case, on the first line, output "Yes" or "No" to indicate whether a valid sequence of operations exists.

翻译中…

You can output the answer in any case (upper or lower). For example, the strings "yEs", "yes", "Yes", and "YES" will be recognized as positive responses.

翻译中…

样例

Input #1
4
2 1
10
01
1 2
11 11
11011001010
01101011100
1 2
2 3
3 4
4 5
5 6
6 7
7 8
8 9
9 10
10 11
11 1
3 2
110
101
1 2
2 3
3 2
111
111
1 2
2 3
Output #1
Yes
Yes
No
Yes
InputCopy OutputCopy
题目信息
题号
2061H1
时间限制
4 s
内存限制
512 MB
标签
网络流
图匹配
图论

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。