/* package whatever; // don't place package name! */
import java.util.*;
import java.lang.*;
import java.io.*;
class Ideone {
public static int flows[][]=new int[300][300];
public static int maxFlow(int[][] cap, int s, int t) {
for (int flow = 0;;) {
int df
= findPath
(cap,
new boolean[cap.
length], s, t,
Integer.
MAX_VALUE); if (df == 0)
return flow;
flow += df;
}
}
static int findPath(int[][] cap, boolean[] vis, int u, int t, int f) {
if (u == t)
return f;
vis[u] = true;
for (int v = 0; v < vis.length; v++)
if (!vis[v] && cap[u][v] > 0) {
int df
= findPath
(cap, vis, v, t,
Math.
min(f, cap
[u
][v
])); if (df > 0) {
cap[u][v] -= df;
flows[u][v]+=df;
flows[v][u]-=df;
cap[v][u] += df;
return df;
}
}
return 0;
}
// Usage example
public static void main
(String[] args
) { int A=0,B=0;
Scanner in
= new Scanner
(System.
in); int[][] multi = new int[300][300];
for(int i = 0; i <300; i++)
for(int j=0; j<300; j++)
multi[i][j]=-1;
int n = in.nextInt();
int m = in.nextInt();
for(int i=0; i<n; ++i)
{
int a = in.nextInt();
multi[2*n+1][i+1]=a;
A+=a;
}
for(int i=0; i<n; ++i)
{
int b = in.nextInt();
multi[n+i+1][2*n+2]=b;
B+=b;
}
for(int i=1; i<=n; ++i)
{
multi[n+i][i]=100000000;
multi[i][n+i]=100000000;
}
for(int i=0; i<m; ++i)
{
int a = in.nextInt();
int b = in.nextInt();
multi[a][n+b]=1000000000;
multi[n+a][b]=1000000000;
multi[n+b][a]=1000000000;
multi[b][n+a]=1000000000;
}
int ans=maxFlow(multi, 2*n+1, 2*n+2);
if(ans!=A || ans!=B)
else
{
for(int i=1; i<=n; ++i)
{
for(int j=n+1; j<=2*n; ++j)
{
if(multi[i][j]>0)
st=st+flows[i][j]+" ";
else
st=st+"0 ";
}
}
}
}
}
LyogcGFja2FnZSB3aGF0ZXZlcjsgLy8gZG9uJ3QgcGxhY2UgcGFja2FnZSBuYW1lISAqLwoKaW1wb3J0IGphdmEudXRpbC4qOwppbXBvcnQgamF2YS5sYW5nLio7CmltcG9ydCBqYXZhLmlvLio7CgpjbGFzcyBJZGVvbmUgewogIHB1YmxpYyBzdGF0aWMgaW50IGZsb3dzW11bXT1uZXcgaW50WzMwMF1bMzAwXTsKICBwdWJsaWMgc3RhdGljIGludCBtYXhGbG93KGludFtdW10gY2FwLCBpbnQgcywgaW50IHQpIHsKICAgIGZvciAoaW50IGZsb3cgPSAwOzspIHsKICAgICAgaW50IGRmID0gZmluZFBhdGgoY2FwLCBuZXcgYm9vbGVhbltjYXAubGVuZ3RoXSwgcywgdCwgSW50ZWdlci5NQVhfVkFMVUUpOwogICAgICBpZiAoZGYgPT0gMCkKICAgICAgICByZXR1cm4gZmxvdzsKICAgICAgZmxvdyArPSBkZjsKICAgIH0KICB9CiAKICBzdGF0aWMgaW50IGZpbmRQYXRoKGludFtdW10gY2FwLCBib29sZWFuW10gdmlzLCBpbnQgdSwgaW50IHQsIGludCBmKSB7CiAgICBpZiAodSA9PSB0KQogICAgICByZXR1cm4gZjsKICAgIHZpc1t1XSA9IHRydWU7CiAgICBmb3IgKGludCB2ID0gMDsgdiA8IHZpcy5sZW5ndGg7IHYrKykKICAgICAgaWYgKCF2aXNbdl0gJiYgY2FwW3VdW3ZdID4gMCkgewogICAgICAgIGludCBkZiA9IGZpbmRQYXRoKGNhcCwgdmlzLCB2LCB0LCBNYXRoLm1pbihmLCBjYXBbdV1bdl0pKTsKICAgICAgICBpZiAoZGYgPiAwKSB7CiAgICAgICAgICBjYXBbdV1bdl0gLT0gZGY7CiAgICAgICAgICBmbG93c1t1XVt2XSs9ZGY7CiAgICAgICAgICBmbG93c1t2XVt1XS09ZGY7CiAgICAgICAgICBjYXBbdl1bdV0gKz0gZGY7CiAgICAgICAgICByZXR1cm4gZGY7CiAgICAgICAgfQogICAgICB9CiAgICByZXR1cm4gMDsKICB9CiAKICAvLyBVc2FnZSBleGFtcGxlCiAgcHVibGljIHN0YXRpYyB2b2lkIG1haW4oU3RyaW5nW10gYXJncykgewogICAgaW50IEE9MCxCPT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