luogu#P4938. War1
War1
Background
As the XM war is approaching, the ENLIGHTENED headquarters, in order to withstand the attack from RESISTANCE, adjusted the energy value of a Portal in some place so that it can take more hits.
Problem Description
ENLIGHTENED headquarters has Portals, numbered from to . The initial energy value of Portal is . There are LINKs between the Portals. Each LINK connects two different Portals. The two connected Portals can transfer energy to each other. Each Portal can transfer at most a total of energy to the Portals connected to it.
Now, the ENLIGHTENED operation commander wants the energy value of each Portal to become at least , but he does not know whether this is possible, so he asked you. If it is possible, you need to find one feasible energy transfer plan.
Energy can only be transferred directly, not indirectly.
Input Format
The first line contains two integers .
The second line contains integers, where the -th integer represents .
The third line contains integers, where the -th integer represents .
Then follow lines. Each line contains two integers , indicating that there is a LINK between Portal and Portal .
Output Format
If there is a feasible plan, output YES, followed by lines, each containing integers. The number in row and column represents the amount of energy transferred from Portal to Portal . If , output the amount of energy remaining in Portal after transfers. If there are multiple feasible plans, output any one of them.
If there is no feasible plan, output NO.
3 2
1 2 3
0 0 6
1 3
2 3
YES
0 0 1
0 0 2
0 0 3
3 2
1 2 3
0 0 7
1 3
2 3
NO
Hint
For of the testdata, .
For of the testdata, .
For of the testdata, .
For of the testdata, , , and .
Translated by ChatGPT 5