#include <bits/stdc++.h>
using namespace std;
inline long long read() {
  long long s = 0, w = 1;
  char ch = getchar();
  while (!isdigit(ch)) {
    if (ch == '-') w = -1;
    ch = getchar();
  }
  while (isdigit(ch)) s = s * 10 + ch - '0', ch = getchar();
  return s * w;
}
inline void write(long long x) {
  if (x < 0) putchar('-'), x = -x;
  if (x > 9) write(x / 10);
  putchar(x % 10 + '0');
}
const int maxn = 210;
const int inf = 0x3f3f3f3f;
int n, m;
int a[maxn], b[maxn];
struct xx {
  int u, v, w, nex;
  xx() {}
  xx(int u, int v, int nex, int w) : u(u), v(v), nex(nex), w(w) {}
} edge[maxn * 100];
int dep[maxn];
int head[maxn], cnt;
int ans[maxn][maxn];
void add(int u, int v, int w) {
  edge[cnt] = xx(u, v, head[u], w);
  head[u] = cnt++;
  edge[cnt] = xx(v, u, head[v], 0);
  head[v] = cnt++;
}
int bfs(int s, int t) {
  queue<int> Q;
  memset((dep), -1, sizeof(dep));
  dep[s] = 0;
  Q.push(s);
  while (!Q.empty()) {
    int u = Q.front();
    Q.pop();
    for (int i = head[u]; ~i; i = edge[i].nex) {
      if (edge[i].w > 0 && dep[edge[i].v] == -1) {
        dep[edge[i].v] = dep[u] + 1;
        Q.push(edge[i].v);
      }
    }
  }
  return dep[t] != -1;
}
int dfs(int s, int t, int low) {
  int used = 0;
  if (s == t) return low;
  for (int i = head[s]; ~i && used < low; i = edge[i].nex) {
    int v = edge[i].v;
    if (dep[v] == dep[s] + 1 && edge[i].w > 0) {
      int a = dfs(v, t, min(low - used, edge[i].w));
      used += a;
      edge[i].w -= a;
      edge[i ^ 1].w += a;
    }
  }
  if (used == 0) dep[s] = -1;
  return used;
}
int dinic(int s, int t) {
  int ans = 0, tmp;
  while (bfs(s, t)) {
    while (1) {
      tmp = dfs(s, t, inf);
      if (tmp == 0) break;
      ans += tmp;
    }
  }
  return ans;
}
int xx[210], yy[210];
int main() {
  n = read(), m = read();
  int suma = 0, sumb = 0;
  for (int i = 1; i <= n; ++i) {
    a[i] = read();
    suma += a[i];
  }
  for (int i = 1; i <= n; ++i) {
    b[i] = read();
    sumb += b[i];
  }
  memset((head), -1, sizeof(head));
  for (int i = 1; i <= m; ++i) {
    int u = read(), v = read();
    xx[i] = u;
    yy[i] = v;
    add(u, v + n, inf);
    add(v, u + n, inf);
  }
  for (int i = 1; i <= n; ++i) {
    add(0, i, a[i]);
    add(i + n, 2 * n + 1, b[i]);
    add(i, i + n, inf);
  }
  int maxFlow = dinic(0, 2 * n + 1);
  if (maxFlow == suma && maxFlow == sumb) {
    puts("YES");
    for (int i = n + 1; i <= 2 * n; ++i) {
      for (int j = head[i]; ~j; j = edge[j].nex) {
        int v = edge[j].v;
        if (v <= n && v > 0) ans[v][i - n] = edge[j].w;
      }
    }
    for (int i = 1; i <= n; ++i, printf("\n"))
      for (int j = 1; j <= n; ++j) printf("%d ", ans[i][j]);
  } else
    puts("NO");
  return 0;
}
