#include <bits/stdc++.h>
using namespace std;
const long long ff = 4e5 + 15;
const long long M = 998244353;
const long long inf = 1e18 + 1;
const long long N = 1e7;
long long n, m, s, t;
struct Node {
  long long fir[ff], nex[ff], to[ff], tot, va[ff], cost[ff];
  void add(long long x, long long y, long long z, long long w) {
    nex[++tot] = fir[x];
    fir[x] = tot;
    to[tot] = y;
    va[tot] = z;
    cost[tot] = w;
  }
  void ade(long long x, long long y, long long z, long long w) {
    add(x, y, z, w);
    add(y, x, 0, -w);
  }
  long long vis[ff], flow[ff], dis[ff], id[ff], pre[ff];
  long long bfs() {
    for (long long i = 1; i <= 1e5; ++i)
      vis[i] = id[i] = 0, pre[i] = -1, flow[i] = dis[i] = inf;
    queue<long long> q;
    q.push(s);
    dis[s] = 0;
    while (!q.empty()) {
      long long u = q.front();
      q.pop();
      vis[u] = 0;
      for (long long i = fir[u]; i; i = nex[i])
        if (va[i] > 0)
          if (dis[to[i]] > dis[u] + cost[i]) {
            dis[to[i]] = dis[u] + cost[i];
            pre[to[i]] = u;
            id[to[i]] = i;
            flow[to[i]] = min(flow[u], va[i]);
            if (!vis[to[i]]) vis[to[i]] = 1, q.push(to[i]);
          }
    }
    if (pre[t] == -1) return 0;
    return 1;
  }
  pair<long long, long long> solve() {
    long long Ans1 = 0, Ans2 = 0;
    while (bfs()) {
      Ans1 += flow[t];
      Ans2 += flow[t] * dis[t];
      long long now = t;
      while (now != -1) {
        va[id[now]] -= flow[t];
        va[id[now] ^ 1] += flow[t];
        now = pre[now];
      }
    }
    return make_pair(Ans1, Ans2);
  }
} isap;
long long a[ff], b[ff], va1[ff], va2[ff];
long long ans[233][233];
long long u[ff], v[ff], id[ff], idd[ff], st[ff];
void init() {
  isap.tot = 1;
  cin >> n >> m;
  long long sum = 0, sq = 0;
  for (long long i = 1; i <= n; ++i) scanf("%lld", &a[i]), sq += a[i];
  for (long long i = 1; i <= n; ++i) scanf("%lld", &b[i]), sum += b[i];
  if (sum != sq) {
    cout << "NO";
    return;
  }
  for (long long i = 1; i <= m; ++i) {
    scanf("%lld %lld", &u[i], &v[i]);
    long long uu = u[i], vv = v[i];
    isap.ade(uu, vv + n, a[uu], 0), id[i] = isap.tot ^ 1, st[i] = a[uu];
    isap.ade(vv, uu + n, a[vv], 0), id[i + m] = isap.tot ^ 1, st[i + m] = a[vv];
  }
  for (long long i = 1; i <= n; ++i)
    isap.ade(i, i + n, a[i], 0), idd[i] = isap.tot ^ 1;
  s = n + n + 1, t = s + 1;
  for (long long i = 1; i <= n; ++i) isap.ade(s, i, a[i], 0);
  for (long long i = 1; i <= n; ++i) isap.ade(i + n, t, b[i], 0);
  long long sss = isap.solve().first;
  if (sss != sum) {
    puts("NO");
    return;
  }
  for (long long i = 1; i <= m; ++i) ans[u[i]][v[i]] = st[i] - isap.va[id[i]];
  for (long long i = m + 1; i <= m + m; ++i)
    ans[v[i - m]][u[i - m]] = st[i] - isap.va[id[i]];
  for (long long i = 1; i <= n; ++i) ans[i][i] = a[i] - isap.va[idd[i]];
  cout << "YES\n";
  for (long long i = 1; i <= n; ++i) {
    for (long long j = 1; j <= n; ++j) cout << ans[i][j] << " ";
    cout << "\n";
  }
}
signed main() {
  long long Ts = 1;
  for (long long i = 1; i <= Ts; ++i) init();
  while ((double)clock() / CLOCKS_PER_SEC <= 0.9) ++n;
}
