#DSU0000040. Chuyển giá trị trên đồ thị (Values)
Bài tập thuộc lộ trình
Mục lục đề ⌄
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 vertices and edges. Vertex initially holds an integer and must eventually hold the target value . Values may be negative, zero, or positive.
In one operation, choose an edge joining vertices and . Increase the value at one endpoint by and decrease the value at the other endpoint by . 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 . The second and third lines contain arrays and . Each of the next lines contains the endpoints of an undirected edge.
Output
Print Yes if possible, otherwise No.
Subtasks
- Subtask 1 (20 points): , ; ; , ; the graph is simple, with no duplicate edges.
- Subtask 2 (30 points): , ; ; , ; the graph is simple, with no duplicate edges.
- Subtask 3 (50 points): , ; ; , ; 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.