P28876 [洛谷] War1
提高+
题目描述

Background

As the XM War approaches, ENLIGHTENED Headquarters has adjusted the energy values of certain Portals in an area to withstand more attacks from the RESISTANCE.

Problem Description

ENLIGHTENED Headquarters has $N$ Portals, numbered from $1$ to $N$. The initial energy value of the Portal numbered $i$ is $A[i]$. There are $M$ LINKS between the Portals, each connecting two different Portals. The connected Portals can transfer energy to each other. Each Portal can only transfer a total of $A[i]$ energy points to its connected Portals. Now, the ENLIGHTENED Action Command wants to ensure that the energy value of each Portal numbered $i$ is at least $B[i]$, but he is unsure if this is feasible. He has asked you to determine if a feasible energy transfer plan exists, and if so, to provide one such plan.

Energy can only be transferred directly, not indirectly.

Input Format

The first line contains two integers $N$ and $M$.

The second line contains $N$ integers, where the $i$-th integer represents $A[i]$.

The third line contains $N$ integers, where the $i$-th integer represents $B[i]$.

The next $M$ lines each contain two integers $X$ and $Y$, indicating that there is a LINK between the Portal numbered $X$ and the Portal numbered $Y$.

Output Format

If a feasible plan exists, output YES, followed by $N$ lines, each containing $N$ integers. The $i$-th line's $j$-th integer represents the amount of energy transferred from the Portal numbered $i$ to the Portal numbered $j$. If $i = j$, output the remaining energy value of the $i$-th Portal after the transfer. If there are multiple feasible plans, output any one of them.

If no feasible plan exists, output NO.

Sample Input and Output

Sample Input #1

3 2 
1 2 3
0 0 6
1 3
2 3

Sample Output #1

YES
0 0 1
0 0 2
0 0 3

Sample Input #2

3 2 
1 2 3
0 0 7
1 3
2 3

Sample Output #2

NO

Notes

For $20\%$ of the data, $N \leq 10$.

For $40\%$ of the data, $N \leq 25$.

For $60\%$ of the data, $N \leq 50$.

For $100\%$ of the data, $N \leq 100, M \leq 2*N, 0 \leq A[i], B[i] \leq 100$.

输入格式

见题面 Input 部分

输出格式

见题面 Output 部分

样例输入
3 2 1 2 3 0 0 6 1 3 2 3
样例输出
YES 0 0 1 0 0 2 0 0 3