PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#DSU0000040. Chuyển giá trị trên đồ thị (Values)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Chuyển giá trị trên đồ thị (Values)

Values

Source: AtCoder

Version: Phuoc Hung OJ Extended

Problem Statement

You are given an undirected graph with nn vertices and mm edges. Vertex ii initially holds an integer aia_i and must eventually hold the target value bib_i. Values may be negative, zero, or positive.

In one operation, choose an edge joining vertices uu and vv. Increase the value at one endpoint by 11 and decrease the value at the other endpoint by 11. You may use any edge repeatedly; intermediate vertex values have no additional restrictions.

Determine whether some finite sequence of operations can make the values at all vertices simultaneously equal their respective targets. Units of value cannot be transferred between vertices that belong to different connected components.

Input

The first line contains n,mn,m. The second and third lines contain arrays aa and bb. Each of the next mm lines contains the endpoints u,vu,v of an undirected edge.

Output

Print Yes if possible, otherwise No.

Subtasks

  • Subtask 1 (20 points): 1≤n≤201\le n\le20, 0≤m≤200\le m\le20; −109≤ai,bi≤109-10^9\le a_i,b_i\le10^9; 1≤u,v≤n1\le u,v\le n, u≠vu\ne v; the graph is simple, with no duplicate edges.
  • Subtask 2 (30 points): 1≤n≤42001\le n\le4200, 0≤m≤42000\le m\le4200; −109≤ai,bi≤109-10^9\le a_i,b_i\le10^9; 1≤u,v≤n1\le u,v\le n, u≠vu\ne v; the graph is simple, with no duplicate edges.
  • Subtask 3 (50 points): 1≤n≤2⋅1051\le n\le2\cdot10^5, 0≤m≤2⋅1050\le m\le2\cdot10^5; −109≤ai,bi≤109-10^9\le a_i,b_i\le10^9; 1≤u,v≤n1\le u,v\le n, u≠vu\ne v; the graph is simple, with no duplicate edges.

Examples

Input

3 2
1 2 3
2 2 2
1 2
2 3

Output

Yes

Explanation

Transfer one unit from vertex 3 to vertex 2, then from vertex 2 to vertex 1. This yields the target array (2,2,2), hence Yes.