#include <bits/stdc++.h>
using namespace std;
int g[202][202];
int gg[202][202];
int path[202];
bool bfs() {
  queue<int> q;
  q.push(0);
  for (int i = 0; i < 202; i++) path[i] = -1;
  path[0] = 0;
  while (!q.empty()) {
    int t = q.front();
    q.pop();
    for (int i = 0; i < 202; i++) {
      if (g[t][i] > 0 && path[i] == -1) {
        q.push(i);
        path[i] = t;
      }
    }
  }
  if (path[201] > -1)
    return true;
  else
    return false;
}
int main() {
  std::ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  int a[n];
  int b[n];
  int tt = 0;
  for (int i = 0; i < n; i++) cin >> a[i];
  for (int i = 0; i < n; i++) tt += a[i];
  for (int i = 0; i < n; i++) cin >> b[i];
  for (int i = 0; i < n; i++) {
    g[0][i + 1] = a[i];
    g[101 + i][201] = b[i];
  }
  int x, y;
  for (int i = 0; i < n; i++) {
    g[i + 1][101 + i] = a[i];
  }
  for (int i = 0; i < m; i++) {
    cin >> x >> y;
    g[x][100 + y] = a[x - 1];
    g[y][100 + x] = a[y - 1];
  }
  int f = 0;
  int k;
  for (int i = 0; i < 202; i++)
    for (int j = 0; j < 202; j++) gg[i][j] = g[i][j];
  while (bfs()) {
    m = INT_MAX;
    k = 201;
    while (k != 0) {
      m = min(m, g[path[k]][k]);
      k = path[k];
    }
    f += m;
    k = 201;
    while (k != 0) {
      g[path[k]][k] -= m;
      g[k][path[k]] += m;
      k = path[k];
    }
  }
  int flag = 0;
  for (int i = 0; i < n; i++) {
    int cc = 0;
    for (int j = 0; j < n; j++) cc += gg[i + 1][101 + j] - g[i + 1][101 + j];
    if (cc != a[i]) flag = 1;
  }
  for (int i = 0; i < n; i++) {
    int cc = 0;
    for (int j = 0; j < n; j++) cc += gg[j + 1][101 + i] - g[j + 1][101 + i];
    if (cc != b[i]) flag = 1;
  }
  if ((f != tt) || (flag == 1)) {
    cout << "NO\n";
  } else {
    cout << "YES\n";
    for (int i = 1; i <= n; i++) {
      for (int j = 101; j < 101 + n; j++) {
        cout << gg[i][j] - g[i][j] << " ";
      }
      cout << "\n";
    }
  }
  return 0;
}
