#include <bits/stdc++.h>
using namespace std;
const int Maxn = 200 + 10, Max = 10001;
int n, m, a[Maxn], b[Maxn], cap[Max], ans[Maxn][Maxn], Min[Maxn], Maxf;
vector<int> adj[Maxn], ind[Maxn];
pair<int, int> par[Maxn];
queue<int> q;
bool mark[Maxn];
void bfs(int v) {
  q.push(v), mark[v] = true;
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    for (int i = 0; i < (int)adj[u].size(); i++)
      if (!mark[adj[u][i]] && cap[ind[u][i]] != 0) {
        mark[adj[u][i]] = true;
        q.push(adj[u][i]);
        Min[adj[u][i]] = min(Min[u], cap[ind[u][i]]);
        par[adj[u][i]] = make_pair(u, ind[u][i]);
      }
  }
  return;
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; i++) scanf("%d", &a[i]);
  for (int i = 0; i < n; i++) scanf("%d", &b[i]);
  int u, v;
  for (int i = 0; i < m; i++) {
    scanf("%d%d", &u, &v);
    u--;
    v--;
    adj[2 * u + 1].push_back(2 * v), adj[2 * v + 1].push_back(2 * u);
    ind[2 * u + 1].push_back(4 * i), ind[2 * v + 1].push_back(4 * i + 2);
    adj[2 * v].push_back(2 * u + 1), adj[2 * u].push_back(2 * v + 1);
    ind[2 * v].push_back(4 * i + 1), ind[2 * u].push_back(4 * i + 3);
    cap[4 * i] = cap[4 * i + 2] = Max;
  }
  for (int i = 0; i < n; i++) {
    adj[2 * i].push_back(2 * i + 1);
    ind[2 * i].push_back(4 * m + 2 * i);
    adj[2 * i + 1].push_back(2 * i);
    ind[2 * i + 1].push_back(4 * m + 2 * i + 1);
    cap[4 * m + 2 * i] = a[i];
    if (b[i] - a[i] > 0) {
      adj[2 * i].push_back(2 * n + 1),
          ind[2 * i].push_back(4 * m + 2 * n + 2 * i),
          cap[4 * m + 2 * n + 2 * i] = b[i] - a[i];
      adj[2 * n + 1].push_back(2 * i),
          ind[2 * n + 1].push_back(4 * m + 2 * n + 2 * i + 1);
    } else {
      adj[2 * n].push_back(2 * i), ind[2 * n].push_back(4 * m + 2 * n + 2 * i),
          cap[4 * m + 2 * n + 2 * i] = a[i] - b[i];
      adj[2 * i].push_back(2 * n),
          ind[2 * i].push_back(4 * m + 2 * n + 2 * i + 1);
    }
  }
  do {
    for (int i = 0; i < 2 * n + 2; i++) mark[i] = false, Min[i] = INT_MAX;
    par[2 * n] = make_pair(-1, -1);
    bfs(2 * n);
    if (Min[2 * n + 1] != INT_MAX) {
      u = 2 * n + 1;
      while (par[u].first != -1) {
        cap[par[u].second] -= Min[2 * n + 1],
            cap[par[u].second ^ 1] += Min[2 * n + 1];
        ans[par[u].first][u] += Min[2 * n + 1];
        u = par[u].first;
      }
    }
  } while (Min[2 * n + 1] != INT_MAX);
  bool flag = false;
  for (int i = 4 * m + 2 * n; i < 4 * m + 4 * n; i += 2)
    if (cap[i] != 0) flag = true;
  if (flag) {
    printf("NO\n");
    return 0;
  }
  for (int i = 0; i < 2 * n; i++)
    for (int j = 0; j < 2 * n; j++) {
      int mm = min(ans[i][j], ans[j][i]);
      ans[i][j] -= mm, ans[j][i] -= mm;
    }
  printf("YES\n");
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (i != j)
        printf("%d ", ans[2 * i + 1][2 * j]);
      else
        printf("%d ", a[i] - ans[2 * i][2 * i + 1]);
    }
    printf("\n");
  }
  return 0;
}
