#P6755. [BalticOI 2013] Pipes (Day1)
[BalticOI 2013] Pipes (Day1)
Problem Description
Given an undirected graph with vertices and edges, the graph is guaranteed to be connected. Each vertex currently contains some amount of water. Now, you can perform an operation on an edge:
- Let water flow out: given , suppose the length is and the flow time is , then the total water loss rate is , and the water loss rate at each endpoint of this edge is .
- Let water flow in: given , suppose the length is and the flow time is , then the total water gain rate is , and the water gain rate at each endpoint of this edge is .
Now given this graph and the rate of change of water amount at each vertex, find a construction scheme for the rate of change of water amount on each edge.
Input Format
The first line contains two integers , representing the number of vertices and edges.
The vertices are numbered from to .
The next lines each contain an integer , representing the rate of change of water amount at this vertex; a positive value means gaining water, and a negative value means losing water.
The next lines each contain two integers describing an edge.
Output Format
If no such construction scheme exists, or if there are multiple solutions, output only one integer 0.
If such a scheme exists, output lines, each containing an integer representing the rate of change of water amount on each edge.
Gaining water is positive, losing water is negative.
4 3
-1
1
-3
1
1 2
1 3
1 4
2
-6
2
4 5
1
2
1
2
1 2
2 3
3 4
4 1
1 3
0
Hint
Constraints
For of the testdata, , , . If a solution exists and is unique, each answer is within .
For of the testdata, the graph is a tree.
Notes
Translated from BalticOI 2013 Day1 C Pipes.
Translated by ChatGPT 5