#include <bits/stdc++.h>
int n, m, s, t, cnt, nxt[205], can[205], dep[205], c[205][205], ans[205][205],
    in, out;
std::vector<int> a[205], b[205], f[205], g[205];
void add(int x, int y, int v) {
  a[x].push_back(y);
  a[y].push_back(x);
  b[x].push_back(v);
  b[y].push_back(0);
  f[x].push_back(a[y].size() - 1);
  f[y].push_back(a[x].size() - 1);
  g[x].push_back(1);
  g[y].push_back(0);
}
int bfs(int s, int t, int lim) {
  std::queue<int> q;
  for (int i = 1; i <= cnt; i++) nxt[i] = 1, can[i] = dep[i] = 0;
  dep[s] = 1;
  q.push(s);
  while (!q.empty()) {
    int v = q.front();
    q.pop();
    for (int i = 0; i < a[v].size(); i++) {
      int u = a[v][i];
      if (!dep[u] && b[v][i] >= lim) dep[u] = dep[v] + 1, q.push(u);
    }
  }
  return dep[t] != 0;
}
int dfs(int v, int t, int now, int lim) {
  if (!nxt[v]) now = 0;
  if (v == t || !now) return now;
  int sum = 0;
  for (int i = can[v]; i < a[v].size(); i++) {
    int u = a[v][i];
    if (b[v][i] >= lim && dep[v] + 1 == dep[u]) {
      int k = dfs(u, t, std::min(now, b[v][i]), lim);
      if (k) {
        b[v][i] = b[v][i] - k, b[u][f[v][i]] = b[u][f[v][i]] + k;
        now = now - k, sum = sum + k;
      }
      if (now) ++can[v];
    } else
      ++can[v];
  }
  if (!sum) nxt[v] = 0;
  return sum;
}
int dinic(int s, int t) {
  int ans = 0;
  for (int i = 128; i >= 1; i = i / 2)
    while (bfs(s, t, i)) ans = ans + dfs(s, t, 2000000000, i);
  return ans;
}
int main() {
  scanf("%d%d", &n, &m);
  s = n + n + 1, t = n + n + 2, cnt = n + n + 2;
  for (int i = 1; i <= n; i++) {
    int x;
    scanf("%d", &x);
    in = in + x;
    add(s, i, x);
  }
  for (int i = 1; i <= n; i++) {
    int x;
    scanf("%d", &x);
    out = out + x;
    add(i + n, t, x);
  }
  if (in != out) {
    puts("NO");
    return 0;
  }
  for (int i = 1; i <= m; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    c[x][y] = c[y][x] = 1;
  }
  for (int i = 1; i <= n; i++) c[i][i] = 1;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++)
      if (c[i][j]) add(i, j + n, 1000000000);
  int ss = dinic(s, t);
  if (ss != in)
    puts("NO");
  else {
    puts("YES");
    for (int i = n + 1; i <= n + n; i++)
      for (int j = 0; j < a[i].size(); j++) {
        int x = a[i][j];
        if (!g[i][j]) ans[x][i - n] = b[i][j];
      }
    for (int i = 1; i <= n; i++) {
      for (int j = 1; j <= n; j++) printf("%d ", ans[i][j]);
      puts("");
    }
  }
  return 0;
}
