#include <bits/stdc++.h>
using namespace std;
const int maxn = 200 + 10;
const int inf = 0x3f3f3f3f;
int head[maxn], cur[maxn], d[maxn], a[maxn], ans[maxn][maxn], n, m, sum, s, t,
    k, num;
struct node {
  int v, w, nxt, c;
} e[maxn * maxn * 2];
void adde(int u, int v, int w) {
  e[k].v = v;
  e[k].w = w;
  e[k].c = w;
  e[k].nxt = head[u];
  head[u] = k++;
}
queue<int> q;
int bfs() {
  memcpy(cur, head, sizeof(head));
  memset(d, -1, sizeof(d));
  d[s] = 0;
  q.push(s);
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    for (int i = head[u]; i != -1; i = e[i].nxt) {
      if (e[i].w && d[e[i].v] == -1) {
        q.push(e[i].v);
        d[e[i].v] = d[u] + 1;
      }
    }
  }
  return d[t] != -1;
}
int dfs(int u, int f) {
  if (u == t) return f;
  int ret = 0, tmp;
  for (int &i = cur[u]; i != -1; i = e[i].nxt) {
    if (e[i].w && d[e[i].v] == d[u] + 1 &&
        (tmp = dfs(e[i].v, min(f, e[i].w))) > 0) {
      e[i].w -= tmp;
      e[i ^ 1].w += tmp;
      f -= tmp;
      ret += tmp;
      if (!f) return ret;
    }
  }
  return ret;
}
int dinic() {
  int ans = 0;
  while (bfs()) ans += dfs(s, inf);
  return ans;
}
int main() {
  scanf("%d%d", &n, &m);
  memset(head, -1, sizeof(head));
  k = sum = num = 0;
  s = 0;
  t = 2 * n + 1;
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &a[i]);
    sum += a[i];
    adde(s, i, a[i]);
    adde(i, s, 0);
    adde(i, i + n, inf);
    adde(i + n, i, 0);
  }
  for (int i = 1; i <= n; ++i) {
    int b;
    scanf("%d", &b);
    num += b;
    adde(i + n, t, b);
    adde(t, i + n, 0);
  }
  for (int i = 1; i <= m; ++i) {
    int x, y;
    scanf("%d%d", &x, &y);
    adde(x, y + n, a[x]);
    adde(y + n, x, 0);
    adde(y, x + n, a[y]);
    adde(x + n, y, 0);
  }
  if (sum == num && dinic() == sum) {
    printf("YES\n");
    for (int i = 1; i <= n; ++i) {
      for (int j = head[i]; j != -1; j = e[j].nxt) {
        if (e[j].v != i + n)
          ans[i][e[j].v - n] = e[j ^ 1].w;
        else
          ans[i][i] = e[j ^ 1].w;
      }
    }
    for (int i = 1; i <= n; ++i) {
      for (int j = 1; j <= n; ++j) printf("%d ", ans[i][j]);
      printf("\n");
    }
  } else
    printf("NO\n");
  return 0;
}
