#include <bits/stdc++.h>
using namespace std;
const int MaxN = (int)2e2 + 10;
const int inf = (int)0x7f7f7f7f;
int n, m, s, t, a[MaxN], b[MaxN];
int c[MaxN][MaxN], f[MaxN][MaxN], pre[MaxN], MaxFlow;
bool FindPath() {
  queue<int> Q;
  memset(pre, inf, sizeof pre);
  Q.push(s);
  pre[s] = -1;
  while (Q.size()) {
    int d = Q.front();
    Q.pop();
    for (int i = 0; i <= 2 * n + 1; ++i)
      if (pre[i] == inf && f[d][i] < c[d][i]) {
        pre[i] = d;
        if (i == t) return true;
        Q.push(i);
      }
  }
  return false;
}
void AugmentPath() {
  int v = t;
  int d = inf;
  while (v != s) {
    int p = pre[v];
    d = min(d, c[p][v] - f[p][v]);
    v = p;
  }
  v = t;
  while (v != s) {
    int p = pre[v];
    f[p][v] += d;
    f[v][p] -= d;
    v = p;
  }
  MaxFlow += d;
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; ++i) scanf("%d", &a[i]);
  for (int i = 1; i <= n; ++i) scanf("%d", &b[i]);
  int S1 = 0, S2 = 0;
  for (int i = 1; i <= n; ++i) S1 += a[i], S2 += b[i];
  if (S1 != S2) {
    cout << "NO\n";
    return 0;
  }
  s = 0;
  t = 2 * n + 1;
  while (m--) {
    int u, v;
    scanf("%d%d", &u, &v);
    c[u][v + n] = a[u];
    c[v][u + n] = a[v];
  }
  for (int i = 1; i <= n; ++i) {
    c[i][i + n] = a[i];
    c[s][i] = a[i];
    c[i + n][t] = b[i];
  }
  while (FindPath()) AugmentPath();
  if (MaxFlow == S2) {
    puts("YES");
    for (int i = 1; i <= n; ++i) {
      for (int j = 1; j <= n; ++j) printf("%d ", f[i][j + n]);
      printf("\n");
    }
  } else
    puts("NO");
  return 0;
}
