#include <bits/stdc++.h>
using namespace std;
const int maxn = 205, maxm = 5005;
int n, m, s, t, e, flg, ans, sum1, sum2, st, ed;
int start[maxn], to[maxm], then[maxm], flow[maxm], rev[maxm], dep[maxn],
    vis[maxn], cur[maxn], res[maxn][maxn];
queue<int> q;
inline void add(int x, int y, int f, int r) {
  then[++e] = start[x], start[x] = e, to[e] = y, flow[e] = f, rev[e] = r;
}
inline void addedge(int x, int y, int f) {
  add(x, y, f, e + 2), add(y, x, 0, e);
}
void bfs() {
  while (!q.empty()) q.pop();
  for (int i = 1; i <= t; i++)
    dep[i] = 100000000, vis[i] = 0, cur[i] = start[i];
  dep[s] = 0, q.push(s);
  while (!q.empty()) {
    int x = q.front();
    q.pop();
    vis[x] = 0;
    for (int i = start[x]; i; i = then[i]) {
      int y = to[i];
      if (flow[i] > 0 && dep[y] > dep[x] + 1) {
        dep[y] = dep[x] + 1;
        if (vis[y] == 0) {
          vis[y] = 1;
          q.push(y);
        }
      }
    }
  }
}
int dfs(int x, int flw) {
  if (x == t) {
    flg = 1, ans += flw;
    return flw;
  }
  int rst = flw;
  for (int i = cur[x]; i; i = then[i]) {
    int y = to[i];
    cur[x] = i;
    if (flow[i] > 0 && dep[y] == dep[x] + 1) {
      int newflw = dfs(y, min(rst, flow[i]));
      if (newflw > 0) {
        rst -= newflw;
        flow[i] -= newflw, flow[rev[i]] += newflw;
        if (rst == 0) break;
      } else
        dep[y] = 0;
    }
  }
  return flw - rst;
}
int Dinic(int s, int t) {
  ans = 0;
  while (1) {
    bfs();
    if (dep[t] == 100000000) break;
    flg = 1;
    while (flg) {
      flg = 0;
      dfs(s, 100000000);
    }
  }
  return ans;
}
int main() {
  scanf("%d%d", &n, &m);
  s = 2 * n + 1, t = 2 * n + 2;
  for (int i = 1; i <= n; i++) {
    int x;
    scanf("%d", &x);
    addedge(s, i, x);
    sum1 += x;
  }
  for (int i = 1; i <= n; i++) {
    int x;
    scanf("%d", &x);
    addedge(n + i, t, x);
    sum2 += x;
  }
  st = e + 1;
  for (int i = 1; i <= n; i++) addedge(i, n + i, 100000000);
  for (int i = 1; i <= m; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    addedge(x, n + y, 100000000), addedge(y, n + x, 100000000);
  }
  ed = e;
  if (Dinic(s, t) != sum1 || sum1 != sum2) {
    puts("NO");
    return 0;
  }
  puts("YES");
  for (int i = st; i <= ed; i += 2)
    if (flow[rev[i]] != 0) res[to[rev[i]]][to[i] - n] += flow[rev[i]];
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++) printf("%d%c", res[i][j], j == n ? '\n' : ' ');
  return 0;
}
