#include <bits/stdc++.h>
using namespace std;
int n, m, s, t, E;
int last[201 + 5], vis[201 + 5];
int to[2 * 1000 + 5], cap[2 * 1000 + 5], Next[2 * 1000 + 5], C[2 * 1000 + 5];
void add_edge(int u, int v, int uv, int vu = 0) {
  to[E] = v;
  C[E] = uv;
  cap[E] = uv;
  Next[E] = last[u];
  last[u] = E++;
  to[E] = u;
  C[E] = vu;
  cap[E] = vu;
  Next[E] = last[v];
  last[v] = E++;
}
int dfs(int u, int f) {
  if (u == t) return f;
  if (vis[u]) return 0;
  vis[u] = 1;
  for (int e = last[u]; e != -1; e = Next[e]) {
    int v = to[e];
    if (cap[e]) {
      int ret = dfs(v, min(f, cap[e]));
      if (ret) {
        cap[e] -= ret;
        cap[e ^ 1] += ret;
        return ret;
      }
    }
  }
  return 0;
}
int maxFlow() {
  int flow = 0;
  while (1) {
    for (int i = 0; i <= 2 * n + 2; i++) vis[i] = 0;
    int f = dfs(s, (1 << 30));
    if (!f) break;
    flow += f;
  }
  return flow;
}
int a[200], b[200], M[200][200];
int main() {
  ios_base::sync_with_stdio(0);
  cin >> n >> m;
  for (int i = 0; i < n; i++) cin >> a[i];
  for (int i = 0; i < n; i++) cin >> b[i];
  memset(last, -1, sizeof(last));
  int sum1 = 0, sum2 = 0;
  for (int i = 0; i < m; i++) {
    int x, y;
    cin >> x >> y;
    add_edge(x, y + n, (1 << 30));
    add_edge(y, x + n, (1 << 30));
  }
  for (int i = 1; i <= n; i++) {
    sum1 += a[i - 1];
    sum2 += b[i - 1];
    add_edge(0, i, a[i - 1]);
    add_edge(i + n, 2 * n + 1, b[i - 1]);
    add_edge(i, i + n, (1 << 30));
  }
  s = 0, t = 2 * n + 1;
  int ans = maxFlow();
  if (ans < sum1 || sum1 != sum2) {
    cout << "NO" << endl;
    return 0;
  }
  for (int i = 0; i < E; i++) {
    if (cap[i] < C[i]) {
      int v = to[i];
      int u = to[i ^ 1];
      if (u >= 1 && u <= n && v >= 1 && v <= 2 * n) {
        M[u - 1][v - n - 1] = C[i] - cap[i];
      }
    }
  }
  cout << "YES" << endl;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (j) cout << " ";
      cout << M[i][j];
    }
    cout << endl;
  }
}
