#include <bits/stdc++.h>
using namespace std;
const long long maxn = 1e5 + 5;
const long long maxm = 1e3 + 5;
const long long inf = 0x3f3f3f3f3f3f3f3fll;
namespace IO {
const int SIZE = (1 << 20) + 1;
char ibuf[SIZE], *iS, *iT, obuf[SIZE], *oS = obuf, *oT = obuf + SIZE - 1;
char _st[55];
int _qr = 0;
inline char gc() {
  return (iS == iT ? iT = (iS = ibuf) + fread(ibuf, 1, SIZE, stdin),
          (iS == iT ? EOF : *iS++) : *iS++);
}
inline void qread() {}
template <class T1, class... T2>
inline void qread(T1 &IEE, T2 &...ls) {
  register T1 __ = 0, ___ = 1;
  register char ch;
  while (!isdigit(ch = gc())) ___ = (ch == '-') ? -___ : ___;
  do {
    __ = (__ << 1) + (__ << 3) + (ch ^ 48);
  } while (isdigit(ch = gc()));
  __ *= ___;
  IEE = __;
  qread(ls...);
  return;
}
inline void flush() {
  fwrite(obuf, 1, oS - obuf, stdout);
  oS = obuf;
  return;
}
inline void putc_(char _x) {
  *oS++ = _x;
  if (oS == oT) flush();
}
inline void qwrite() {}
template <class T1, class... T2>
inline void qwrite(T1 IEE, T2... ls) {
  if (!IEE) putc_('0');
  if (IEE < 0) putc_('-'), IEE = -IEE;
  while (IEE) _st[++_qr] = IEE % 10 + '0', IEE /= 10;
  while (_qr) putc_(_st[_qr--]);
  qwrite(ls...);
  return;
}
struct Flusher_ {
  ~Flusher_() { flush(); }
} io_flusher;
}  // namespace IO
using namespace IO;
long long n, m;
long long cur = 1;
long long head[maxn], nex[maxn], to[maxn];
long long cap[maxn];
void add(long long u, long long v, long long cp) {
  nex[++cur] = head[u];
  to[cur] = v;
  cap[cur] = cp;
  head[u] = cur;
  nex[++cur] = head[v];
  to[cur] = u;
  cap[cur] = 0;
  head[v] = cur;
  return;
}
long long ptr[maxn], dis[maxn];
queue<long long> q;
bool bfs() {
  for (int i = 0; i <= 2ll * n + 1; i++) {
    ptr[i] = head[i];
    dis[i] = 0;
  }
  q.push(0);
  dis[0] = 1;
  while (!q.empty()) {
    long long fr = q.front();
    q.pop();
    for (int i = head[fr]; i; i = nex[i]) {
      long long t = to[i];
      if (cap[i] == 0 || dis[t] > 0) continue;
      q.push(t);
      dis[t] = dis[fr] + 1;
      if (t == 2ll * n + 1) {
        while (!q.empty()) q.pop();
        return 1;
      }
    }
  }
  return 0;
}
long long dinic(long long now, long long flow) {
  if (now == 2ll * n + 1) return flow;
  long long sumf = 0;
  for (long long &i = ptr[now]; i; i = nex[i]) {
    long long t = to[i];
    if (cap[i] == 0 || dis[t] != dis[now] + 1) continue;
    long long tmpf = dinic(t, min(cap[i], flow));
    sumf += tmpf;
    if (tmpf > 0) {
      cap[i] -= tmpf;
      cap[i ^ 1] += tmpf;
      flow -= tmpf;
      if (flow == 0) return sumf;
    } else if (tmpf == 0)
      dis[t] = -1;
  }
  return sumf;
}
long long a[maxn], b[maxn];
long long ansf = 0;
long long f[105][105];
int main() {
  qread(n, m);
  long long suma = 0, sumb = 0;
  for (int i = 1; i <= n; i++) {
    qread(a[i]);
    suma += a[i];
    add(0, i, a[i]);
  }
  for (int i = 1; i <= n; i++) {
    qread(b[i]);
    sumb += b[i];
    add(i + n, 2ll * n + 1, b[i]);
  }
  for (int i = 1; i <= m; i++) {
    long long ux, vx;
    qread(ux, vx);
    add(ux, vx + n, inf);
    add(vx, ux + n, inf);
  }
  for (int i = 1; i <= n; i++) {
    add(i, i + n, inf);
  }
  if (suma != sumb) {
    puts("NO");
    return 0;
  }
  while (bfs()) ansf += dinic(0, inf);
  if (ansf < sumb) {
    puts("NO");
    return 0;
  }
  puts("YES");
  for (int i = 1; i <= n; i++) {
    for (int j = head[i]; j; j = nex[j]) {
      if (to[j] == 0) continue;
      f[i][to[j] - n] = cap[j ^ 1];
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      printf("%lld ", f[i][j]);
    }
    puts("");
  }
  return 0;
}
