QOJ.ac

QOJ

実行時間制限: 1 s メモリ制限: 512 MB 満点: 100

#17183. Games on Graphs

統計

Given a connected undirected graph with $n$ vertices and $m$ edges, where all vertices are labeled with integers from $1$ to $n$. Initially, each vertex $u$ has a weight $a_u$. You can perform the following operation any number of times:

  • Choose two vertices $u, v$ such that there is an edge between $u$ and $v$, and set $a_u = \min(a_u, a_v)$.

Given $b_1, \ldots, b_n$, determine whether it is possible to transform $a$ into $b$ through a sequence of operations. If it is possible, output Yes, otherwise output No.

There are $T$ test cases in total.

Input

The first line contains an integer $T$, representing the number of test cases.

For each test case, the first line contains two integers $n$ and $m$.

The second line contains $n$ integers, $a_1, \ldots, a_n$.

The third line contains $n$ integers, $b_1, \ldots, b_n$.

The next $m$ lines each contain two integers $u, v$, representing an edge between $u$ and $v$.

Output

Output $T$ lines, each containing Yes or No, representing the answer for the $i$-th test case.

Examples

Input 1

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

Output 1

Yes
No

Constraints

For $100\%$ of the data, $1\le n\le 1.5\times 10^5$, $1\le m\le 2\times 10^5$, $\sum n\times m \le 5\times 10^6$.

Subtask 1 ($20\%$): It is guaranteed that there exists a vertex connected to all other vertices, and $m = n-1$.

Subtask 2 ($40\%$): It is guaranteed that the graph is a tree.

Subtask 3 ($40\%$): No special restrictions.

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.