#P1537F. Figure Fixing
Figure Fixing
No submission language available for this problem.
Description
You have a connected undirected graph made of nodes and edges. The -th node has a value and a target value .
In an operation, you can choose an edge and add to both and , where can be any integer. In particular, can be negative.
Your task to determine if it is possible that by doing some finite number of operations (possibly zero), you can achieve for every node , .
The first line contains a single integer (), the number of test cases. Then the test cases follow.
The first line of each test case contains two integers , (, ) — the number of nodes and edges respectively.
The second line contains integers () — initial values of nodes.
The third line contains integers () — target values of nodes.
Each of the next lines contains two integers and representing an edge between node and node (, ).
It is guaranteed that the graph is connected and there is at most one edge between the same pair of nodes.
It is guaranteed that the sum of over all testcases does not exceed and the sum of over all testcases does not exceed .
For each test case, if it is possible for every node to reach its target after some number of operations, print "YES". Otherwise, print "NO".
Input
The first line contains a single integer (), the number of test cases. Then the test cases follow.
The first line of each test case contains two integers , (, ) — the number of nodes and edges respectively.
The second line contains integers () — initial values of nodes.
The third line contains integers () — target values of nodes.
Each of the next lines contains two integers and representing an edge between node and node (, ).
It is guaranteed that the graph is connected and there is at most one edge between the same pair of nodes.
It is guaranteed that the sum of over all testcases does not exceed and the sum of over all testcases does not exceed .
Output
For each test case, if it is possible for every node to reach its target after some number of operations, print "YES". Otherwise, print "NO".
Samples
Note
Here is a visualization of the first test case (the orange values denote the initial values and the blue ones the desired values):

One possible order of operations to obtain the desired values for each node is the following:
- Operation : Add to nodes and .
- Operation : Add to nodes and .
- Operation : Add to nodes and .
Now we can see that in total we added to node , to node , to node and to node which brings each node exactly to it's desired value.
For the graph from the second test case it's impossible to get the target values.