#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7, inf = 1061109567;
const long long infll = 4557430888798830399;
int n;
int a[222][222] = {0}, vis[222] = {0};
int dfs(int x, int cp) {
  if (x == 221) return cp;
  if (vis[x]) return 0;
  vis[x] = 1;
  for (int i = 0; i <= 221; i += 1) {
    if (a[x][i]) {
      int t = dfs(i, min(cp, a[x][i]));
      if (t) {
        a[x][i] -= t;
        a[i][x] += t;
        return t;
      }
    }
  }
  return 0;
}
signed main() {
  int m;
  cin >> n >> m;
  int suma = 0, sumb = 0;
  for (int i = 0; i <= n - 1; i += 1) {
    cin >> a[220][i];
  }
  for (int i = 0; i <= n - 1; i += 1) {
    cin >> a[i + n][221];
  }
  for (int i = 0; i <= n - 1; i += 1) {
    a[i][i + n] = inf;
  }
  while (m--) {
    int u, v;
    cin >> u >> v;
    a[u - 1][v + n - 1] = a[v - 1][u + n - 1] = inf;
  }
  while (dfs(220, inf)) {
    for (int i = 0; i <= 221; i += 1) vis[i] = 0;
  }
  for (int i = 0; i <= n - 1; i += 1) {
    if (a[220][i] || a[i + n][221]) {
      return cout << "NO", 0;
    }
  }
  cout << "YES\n";
  for (int i = 0; i <= n - 1; i += 1) {
    for (int j = 0; j <= n - 1; j += 1) {
      cout << a[j + n][i] << " ";
    }
    cout << "\n";
  }
}
