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 NN Portals, numbered from 11 to NN. The initial energy value of Portal ii is AiA_i. There are MM 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 AiA_i energy to the Portals connected to it.

Now, the ENLIGHTENED operation commander wants the energy value of each Portal ii to become at least BiB_i, 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 N,MN, M.

The second line contains NN integers, where the ii-th integer represents AiA_i.

The third line contains NN integers, where the ii-th integer represents BiB_i.

Then follow MM lines. Each line contains two integers X,YX, Y, indicating that there is a LINK between Portal XX and Portal YY.

Output Format

If there is a feasible plan, output YES, followed by NN lines, each containing NN integers. The number in row ii and column jj represents the amount of energy transferred from Portal ii to Portal jj. If i=ji = j, output the amount of energy remaining in Portal ii 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 20%20\% of the testdata, N10N \leq 10.

For 40%40\% of the testdata, N25N \leq 25.

For 60%60\% of the testdata, N50N \leq 50.

For 100%100\% of the testdata, N100N \leq 100, M2NM \leq 2 * N, and 0Ai,Bi1000 \leq A_i, B_i \leq 100.

Translated by ChatGPT 5