#include <bits/stdc++.h>
using namespace std;
const int N = 504;
struct E {
  int next, to, val;
} e[N << 2];
int n, m, head[N], tot = 0, INF = 1000000;
void add(int x, int y, int z) {
  e[tot] = E{y, head[x], z};
  head[x] = tot++;
  e[tot] = E{x, head[y], 0};
  head[y] = tot++;
}
int st, ed, d[N];
bool bfs() {
  memset(d, 0, sizeof(d));
  queue<int> q;
  q.push(st);
  d[st] = 1;
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    for (int i = head[u]; ~i; i = e[i].to) {
      int v = e[i].next;
      if (e[i].val == 0 || d[v]) continue;
      d[v] = d[u] + 1;
      q.push(v);
      if (v == ed) return 1;
    }
  }
  return 0;
}
int dinic(int u, int flow) {
  if (u == ed) return flow;
  int rest = flow, k;
  for (int i = head[u]; (~i) && rest; i = e[i].to) {
    int v = e[i].next;
    if (e[i].val == 0 || d[v] != d[u] + 1) continue;
    k = dinic(v, min(rest, e[i].val));
    if (k == 0) d[v] = 0;
    e[i].val -= k;
    e[i ^ 1].val += k;
    rest -= k;
  }
  return flow - rest;
}
int s1 = 0, s2 = 0, mp[N][N];
bool solve() {
  if (s1 != s2) return 0;
  int t, sum = 0;
  while (bfs())
    while (t = dinic(st, INF)) sum += t;
  if (sum != s2) return 0;
  for (int i = 1; i <= n; i++)
    for (int j = head[i]; ~j; j = e[j].to) {
      int v = e[j].next;
      if (v > n && v <= n + n) mp[i][v - n] = INF - e[j].val;
    }
  return 1;
}
int main() {
  memset(head, -1, sizeof(head));
  int s, x, y, z;
  scanf("%d %d", &n, &m);
  st = 0;
  ed = n + n + 1;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &x);
    s1 += x;
    add(st, i, x);
    add(i, i + n, INF);
  }
  for (int i = 1; i <= n; i++) {
    scanf("%d", &x);
    s2 += x;
    add(i + n, ed, x);
  }
  for (int i = 1; i <= m; i++) {
    scanf("%d %d", &x, &y);
    add(x, y + n, INF);
    add(y, x + n, INF);
  }
  if (solve()) {
    puts("YES");
    for (int i = 1; i <= n; i++)
      for (int j = 1; j <= n; j++) printf("%d%c", mp[i][j], " \n"[j == n]);
  } else
    puts("NO");
}
