#include <bits/stdc++.h>
#pragma comment(linker, '/STACK:200000')
const int INF = 1e9 + 7;
const double EPS = 1e-9;
const double pi = acos(-1);
const int MOD = 1e9 + 7;
const int N = 1e5 + 1000;
using namespace std;
struct edge {
  int a, b, cap, flow;
  edge() { a = b = cap = flow = 0; }
  edge(int aa, int bb, int c) {
    a = aa;
    b = bb;
    cap = c;
    flow = 0;
  }
};
vector<edge> e;
vector<int> g[N];
int csz, d[N], ptr[N], q[N], qs, qt, st, ed;
map<pair<int, int>, int> e_id;
void add_edge(int a, int b, int c) {
  g[a].emplace_back((int)e.size());
  e_id[make_pair(a, b)] = (int)e.size();
  e.emplace_back(edge(a, b, c));
  g[b].emplace_back((int)e.size());
  e.emplace_back(edge(b, a, 0));
}
bool Bfs() {
  qs = qt = 0;
  for (int i = 0; i <= csz; i++) d[i] = -1;
  d[st] = 0;
  q[qt++] = st;
  while (qs < qt && d[ed] == -1) {
    int v = q[qs++];
    for (auto id : g[v]) {
      int to = e[id].b;
      if (d[to] == -1 && (e[id].cap > e[id].flow))
        d[to] = d[v] + 1, q[qt++] = to;
    }
  }
  return (d[ed] != -1);
}
int Dfs(int v, int flow) {
  if (!flow) return 0;
  if (v == ed) return flow;
  for (; ptr[v] < (int)g[v].size(); ptr[v]++) {
    int id = g[v][ptr[v]], to = e[id].b;
    if (d[to] != d[v] + 1) continue;
    int push = Dfs(to, min(flow, e[id].cap - e[id].flow));
    if (push) {
      e[id].flow += push;
      e[id ^ 1].flow -= push;
      return push;
    }
  }
  return 0;
}
int Get() {
  int res = 0;
  while (1) {
    if (!Bfs()) break;
    for (int i = 0; i <= csz; i++) ptr[i] = 0;
    while (int cur = Dfs(st, INF)) res += cur;
  }
  return res;
}
int idb[N], ida[N];
int Id1(int x) {
  if (!ida[x]) return ida[x] = csz++;
  return ida[x];
}
int Id2(int x) {
  if (!idb[x]) return idb[x] = csz++;
  return idb[x];
}
int a[N], b[N], n, m, ans[333][333], aa[N];
bool Check() {
  for (int i = 1; i <= n; i++) aa[i] = a[i];
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++) aa[i] -= ans[i][j], aa[j] += ans[i][j];
  for (int i = 1; i <= n; i++)
    if (aa[i] != b[i]) return 0;
  return 1;
}
int main() {
  cin.tie(0);
  ios_base ::sync_with_stdio(0);
  st = csz++;
  ed = csz++;
  int sum = 0;
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    sum += a[i];
  }
  for (int j = 1; j <= n; j++) cin >> b[j];
  bool ok = 1;
  for (int i = 1; i <= n; i++) ok &= (a[i] == b[i]);
  if (ok) {
    cout << "YES\n";
    for (int i = 1; i <= n; i++)
      for (int j = 1; j <= n; j++) cout << (i == j ? a[i] : 0) << " \n"[j == n];
    return 0;
  }
  int x, y;
  for (int i = 1; i <= n; i++) add_edge(st, Id1(i), a[i]);
  for (int i = 1; i <= n; i++) add_edge(Id2(i), ed, b[i]);
  for (int i = 1; i <= n; i++) add_edge(Id1(i), Id2(i), a[i]);
  for (int i = 0; i < m; i++) {
    cin >> x >> y;
    add_edge(Id1(x), Id2(y), b[y]);
    add_edge(Id1(y), Id2(x), a[y]);
  }
  if (Get() == sum) {
    for (int i = 1; i <= n; i++)
      for (int j = 1; j <= n; j++) {
        int f = Id1(i), s = Id2(j);
        if (e_id.count(make_pair(f, s)))
          ans[i][j] = e[e_id[make_pair(f, s)]].flow;
        else
          ans[i][j] = 0;
      }
    if (Check()) {
      cout << "YES\n";
      for (int i = 1; i <= n; i++)
        for (int j = 1; j <= n; j++) cout << ans[i][j] << " \n"[j == n];
    } else
      cout << "NO\n";
  } else
    cout << "NO\n";
  return 0;
}
