#P6755. [BalticOI 2013] Pipes (Day1)

    ID: 7535 远端评测题 1000ms 128MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>搜索图论2013BalticOI(波罗的海)

[BalticOI 2013] Pipes (Day1)

Problem Description

Given an undirected graph with NN vertices and MM 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 dd, suppose the length is mm and the flow time is ss, then the total water loss rate is 2dm3s\dfrac{2dm^3}{s}, and the water loss rate at each endpoint of this edge is dm3s\dfrac{dm^3}{s}.
  • Let water flow in: given pp, suppose the length is mm and the flow time is ss, then the total water gain rate is 2pm3s\dfrac{2pm^3}{s}, and the water gain rate at each endpoint of this edge is pm3s\dfrac{pm^3}{s}.

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 N,MN,M, representing the number of vertices and edges.
The NN vertices are numbered from 11 to NN.
The next NN lines each contain an integer cic_i, 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 MM 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 MM 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 100%100\% of the testdata, 1N1051 \le N \le 10^5, 1M5×1051 \le M \le 5 \times 10^5, 109ci109-10^9 \le c_i \le 10^9. If a solution exists and is unique, each answer is within [109,109][-10^9,10^9].
For 30%30\% of the testdata, the graph is a tree.

Notes

Translated from BalticOI 2013 Day1 C Pipes.

Translated by ChatGPT 5