#include <bits/stdc++.h>
const long long N = 301, mod = 998244353;
using namespace std;
long long n, m, i, j, k, l, r, t, x[N], a[N][N], b[N][N], y[N], ans, sum, sx,
    sy;
bool fix[N];
double d;
bool go(long long u, long long flow) {
  fix[u] = 1;
  if (u == m) return 1;
  for (long long i = 0; i <= m; i++) {
    if (!fix[i] && b[u][i] + flow <= a[u][i]) {
      if (go(i, flow)) {
        b[u][i] += flow;
        b[i][u] -= flow;
        return 1;
      }
    }
  }
  return 0;
}
long long MF() {
  long long i, j, ans = 0;
  sum = 0;
  for (i = 0; i <= m; i++) sum += a[1][i];
  for (i = 0; i <= m; i++)
    for (j = 0; j <= m; j++) b[i][j] = 0;
  while (sum) {
    for (i = 0; i <= m; i++) fix[i] = 0;
    if (go(0, sum))
      ans += sum;
    else
      sum /= 2;
  }
  return ans;
}
int main() {
  cin >> n >> k;
  m = 2 * n + 1;
  for (i = 1; i <= n; i++) {
    a[i][i + n] = mod;
    cin >> x[i];
    sx += x[i];
    a[0][i] = x[i];
  }
  for (i = 1; i <= n; i++) {
    cin >> y[i];
    sy += y[i];
    a[i + n][m] = y[i];
  }
  if (sy != sx) {
    cout << "NO\n";
    return 0;
  }
  while (k--) {
    cin >> l >> r;
    a[l][r + n] = mod;
    a[r][l + n] = mod;
  }
  k = MF();
  if (k != sy) {
    cout << "NO\n";
    return 0;
  }
  cout << "YES\n";
  for (i = 1; i <= n; i++) {
    for (j = n + 1; j <= n * 2; j++) {
      cout << b[i][j] << " ";
    }
    cout << endl;
  }
  return 0;
}
