#include <bits/stdc++.h>
using namespace std;
int n, m, a[110], b[110], i, j, k, s, t, T = 1;
struct edge {
  int y, l, z;
} f[210 * 4 + 110 * 8];
int g[110 * 2];
void INS(int u, int v, int z) {
  f[++T].y = v, f[T].l = g[u], g[u] = T, f[T].z = z;
  f[++T].y = u, f[T].l = g[v], g[v] = T, f[T].z = 0;
}
int D[110 * 2], di[110 * 2], vh[110 * 2];
int sap(int po, int aug) {
  int used = 0, k;
  if (po == t) return aug;
  for (k = di[po]; k; k = f[k].l)
    if (f[k].z > 0 && D[po] == D[f[k].y] + 1) {
      di[po] = k;
      int tmp = sap(f[k].y, min(aug - used, f[k].z));
      used += tmp;
      f[k].z -= tmp;
      f[k ^ 1].z += tmp;
      if (D[s] > n || used == aug) return used;
    }
  if (--vh[D[po]] == 0) {
    D[s] = n + 1;
    return used;
  }
  di[po] = g[po];
  ++vh[++D[po]];
  return used;
}
int fr = 0;
struct Recorder {
  int k, a, b;
} rec[210 * 4 + 110 * 8];
int G[110][110];
int main() {
  scanf("%d%d", &n, &m);
  s = 1 + n + n, t = 1 + s;
  int sig = 0, A = 0;
  for (i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    INS(s, i, a[i]);
    A += a[i];
  }
  for (i = 1; i <= n; i++) {
    scanf("%d", &b[i]);
    INS(i + n, t, b[i]);
    sig += b[i];
  }
  for (i = 1; i <= m; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    rec[++fr].k = T + 1, rec[fr].a = x, rec[fr].b = y;
    INS(x, n + y, 0x7fffffff);
    rec[++fr].k = T + 1, rec[fr].a = y, rec[fr].b = x;
    INS(y, x + n, 0x7fffffff);
  }
  for (i = 1; i <= n; i++) {
    rec[++fr].k = T + 1, rec[fr].a = i, rec[fr].b = i;
    INS(i, n + i, 0x7fffffff);
  }
  n = t;
  vh[0] = n;
  for (i = 1; i <= n; i++) di[i] = g[i];
  int flow = 0;
  while (D[s] <= n) flow += sap(s, 0x7fffffff);
  if (flow != sig || A > sig) {
    puts("NO");
    return 0;
  } else {
    n = (n - 2) / 2;
    puts("YES");
    for (i = 1; i <= fr; i++)
      G[rec[i].a][rec[i].b] += 0x7fffffff - f[rec[i].k].z;
    for (i = 1; i <= n; i++) {
      for (j = 1; j <= n; j++) printf("%d ", G[i][j]);
      printf("\n");
    }
  }
}
