#include <bits/stdc++.h>
using namespace std;
struct node {
  int f, v, c, t, op;
  void init(int _f, int _v, int _c, int _t, int _op) {
    f = _f;
    v = _v;
    c = _c;
    t = _t;
    op = _op;
  }
};
vector<node> a[1010];
int tr[1010], pos[1010];
int n, m, s, t, p, nq;
int flow = 0;
int que[1010];
bool findPath() {
  memset(tr, -1, sizeof(tr));
  memset(pos, 0, sizeof(pos));
  int r = 1;
  int l = 1;
  que[r] = s;
  tr[s] = 0;
  while (l <= r) {
    int u = que[l];
    l++;
    for (int i = 0; i < a[u].size(); i++) {
      node x = a[u][i];
      if (tr[x.v] != -1) continue;
      int cap;
      if (x.t == 1)
        cap = x.c - x.f;
      else
        cap = 0 - x.f;
      if (cap == 0) continue;
      r++;
      que[r] = x.v;
      tr[x.v] = u;
      pos[x.v] = i;
      if (x.v == t) return (true);
    }
  }
  return false;
}
void incFlow() {
  int p = 1000000000;
  int x = t;
  while (true) {
    int ps = pos[x];
    int u = tr[x];
    if (a[u][ps].t == 1)
      p = min(p, a[u][ps].c - a[u][ps].f);
    else
      p = min(p, 0 - a[u][ps].f);
    x = u;
    if (x == s) break;
  }
  flow += p;
  x = t;
  while (true) {
    int ps = pos[x];
    int u = tr[x];
    int _ps = a[u][ps].op;
    int _u = x;
    a[u][ps].f += p;
    a[_u][_ps].f -= p;
    x = u;
    if (x == s) break;
  }
}
void add(int u, int v, int c) {
  node x, y;
  x.init(0, v, c, 1, a[v].size());
  y.init(0, u, 0, -1, a[u].size());
  a[u].push_back(x);
  a[v].push_back(y);
}
int a1[1010], a2[1010];
int maxFlow = 0;
int flow2 = 0;
int ans[1010][1010];
int main() {
  ios::sync_with_stdio(false);
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    cin >> a1[i];
    maxFlow += a1[i];
  }
  for (int i = 1; i <= n; i++) {
    cin >> a2[i];
    flow2 += a2[i];
  }
  for (int i = 1; i <= n; i++) add(0, i, a1[i]);
  for (int i = 1; i <= n; i++) add(i + n, 2 * n + 1, a2[i]);
  for (int i = 1; i <= m; i++) {
    int u, v;
    cin >> u >> v;
    add(u, v + n, 10000);
    add(v, u + n, 10000);
  }
  for (int i = 1; i <= n; i++) add(i, i + n, 10000);
  s = 0;
  t = 2 * n + 1;
  while (findPath()) incFlow();
  if (flow2 != maxFlow)
    cout << "NO";
  else if (flow != maxFlow)
    cout << "NO";
  else {
    cout << "YES\n";
    for (int i = 1; i <= n; i++) {
      for (int j = 0; j < a[i].size(); j++) ans[i][a[i][j].v - n] = a[i][j].f;
    }
    for (int i = 1; i <= n; i++) {
      for (int j = 1; j <= n; j++) cout << ans[i][j] << " ";
      cout << "\n";
    }
  }
  return 0;
}
