CF1537F.Figure Fixing
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You have a connected undirected graph made of n nodes and m edges. The i -th node has a value vi and a target value ti .
In an operation, you can choose an edge (i,j) and add k to both vi and vj , where k can be any integer. In particular, k 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 i , vi=ti .
输入格式
The first line contains a single integer t ( 1≤t≤1000 ), the number of test cases. Then the test cases follow.
The first line of each test case contains two integers n , m ( 2≤n≤2⋅105 , n−1≤m≤min(2⋅105,2n(n−1)) ) — the number of nodes and edges respectively.
The second line contains n integers v1…,vn ( −109≤vi≤109 ) — initial values of nodes.
The third line contains n integers t1…,tn ( −109≤ti≤109 ) — target values of nodes.
Each of the next m lines contains two integers i and j representing an edge between node i and node j ( 1≤i,j≤n , i=j ).
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 n over all testcases does not exceed 2⋅105 and the sum of m over all testcases does not exceed 2⋅105 .
输出格式
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".
输入输出样例
输入#1
2 4 4 5 1 2 -3 3 3 10 1 1 2 1 4 3 2 3 4 4 4 5 8 6 6 -3 1 15 4 1 2 1 4 3 2 3 4
输出#1
YES NO
说明/提示
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 1 : Add 2 to nodes 2 and 3 .
- Operation 2 : Add −2 to nodes 1 and 4 .
- Operation 3 : Add 6 to nodes 3 and 4 .
Now we can see that in total we added −2 to node 1 , 2 to node 2 , 8 to node 3 and 4 to node 4 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.