ARC106B - Values
You cannot submit for this problem because the contest is ended. You can click "Open in Problem Set" to view this problem in normal mode.
Score : 400 points
Problem Statement
Given is a simple undirected graph with N vertices and M edges. The i-th edge connects Vertex ci and Vertex di. Initially, Vertex i has the value ai written on it. You want to change the values on Vertex 1, …, Vertex N to b1, ⋯, bN, respectively, by doing the operation below zero or more times.
- Choose an edge, and let Vertex x and Vertex y be the vertices connected by that edge. Choose one of the following and do it:
- Decrease the value ax by 1, and increase the value ay by 1.
- Increase the value ax by 1, and decrease the value ay by 1.
Determine whether it is possible to achieve the objective by properly doing the operation.
Constraints
- 1≤N≤2×105
- 0≤M≤2×105
- −109≤ai,bi≤109
- 1≤ci,di≤N
- The given graph is simple, that is, has no self-loops and no multi-edges.
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
N M a1 ⋯ aN b1 ⋯ bN c1 d1 ⋮ cM dM
Output
Print Yes
if it is possible to achieve the objective by properly doing the operation, and No
otherwise.
Sample Input 1
3 2 1 2 3 2 2 2 1 2 2 3
Sample Output 1
Yes
You can achieve the objective by, for example, doing the operation as follows:
- In the first operation, choose the edge connecting Vertex 1 and 2. Then, increase a1 by 1 and decrease a2 by 1.
- In the second operation, choose the edge connecting Vertex 2 and 3. Then, increase a2 by 1 and decrease a3 by 1.
This sequence of operations makes a1=2, a2=2, and a3=2.
Sample Input 2
1 0 5 5
Sample Output 2
Yes
The objective may be achieved already in the beginning.
Sample Input 3
2 1 1 1 2 1 1 2
Sample Output 3
No
There is no way to do the operation to achieve the objective.
Sample Input 4
17 9 -905371741 -999219903 969314057 -989982132 -87720225 -175700172 -993990465 929461728 895449935 -999016241 782467448 -906404298 578539175 9684413 -619191091 -952046546 125053320 -440503430 -997661446 -912471383 -995879434 932992245 -928388880 -616761933 929461728 210953513 -994677396 648190629 -530944122 578539175 9684413 595786809 -952046546 125053320 2 10 6 12 9 11 11 5 7 6 3 15 3 1 1 9 10 4
Sample Output 4
Yes
ARC106
- Status
- Done
- Rule
- IOI
- Problem
- 6
- Start at
- 2023-7-5 8:15
- End at
- 2023-7-5 10:15
- Duration
- 2 hour(s)
- Host
- Partic.
- 13