atcoder#ARC106B. [ARC106B] Values

[ARC106B] Values

Score : 400400 points

Problem Statement

Given is a simple undirected graph with NN vertices and MM edges. The ii-th edge connects Vertex cic_i and Vertex did_i. Initially, Vertex ii has the value aia_i written on it. You want to change the values on Vertex 11, \ldots, Vertex NN to b1b_1, \cdots, bNb_N, respectively, by doing the operation below zero or more times.

  • Choose an edge, and let Vertex xx and Vertex yy be the vertices connected by that edge. Choose one of the following and do it:- Decrease the value axa_x by 11, and increase the value aya_y by 11.
    • Increase the value axa_x by 11, and decrease the value aya_y by 11.
  • Decrease the value axa_x by 11, and increase the value aya_y by 11.
  • Increase the value axa_x by 11, and decrease the value aya_y by 11.

Determine whether it is possible to achieve the objective by properly doing the operation.

Constraints

  • 1N2×1051 \leq N \leq 2 \times 10^5
  • 0M2×1050 \leq M \leq 2 \times 10^5
  • 109ai,bi109-10^9 \leq a_i,b_i \leq 10^9
  • 1ci,diN1 \leq c_i,d_i \leq 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:

NN MM

a1a_1 \cdots aNa_N

b1b_1 \cdots bNb_N

c1c_1 d1d_1

\vdots

cMc_M dMd_M

Output

Print Yes if it is possible to achieve the objective by properly doing the operation, and No otherwise.

3 2
1 2 3
2 2 2
1 2
2 3
Yes

You can achieve the objective by, for example, doing the operation as follows:

  • In the first operation, choose the edge connecting Vertex 11 and 22. Then, increase a1a_1 by 11 and decrease a2a_2 by 11.
  • In the second operation, choose the edge connecting Vertex 22 and 33. Then, increase a2a_2 by 11 and decrease a3a_3 by 11.

This sequence of operations makes a1=2a_1=2, a2=2a_2=2, and a3=2a_3=2.

1 0
5
5
Yes

The objective may be achieved already in the beginning.

2 1
1 1
2 1
1 2
No

There is no way to do the operation to achieve the objective.

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
Yes