#include <bits/stdc++.h>
using namespace std;
const int N = 500005;
const int M = 5000;
const int Bases = 2;
const long long base[] = {137, 37};
const long long mod = 1000000007LL;
long long addi(long long a, long long b, long long m = mod) {
  a += b;
  if (a < 0) a += m;
  if (a >= m) a -= m;
  return a;
}
long long subt(long long a, long long b, long long m = mod) {
  a -= b;
  if (a < 0) a += m;
  if (a >= m) a -= m;
  return a;
}
long long mult(long long a, long long b, long long m = mod) {
  if (b == 0) return 0;
  long long tmp = mult(a, b >> 1, m);
  tmp = addi(tmp, tmp, m);
  return (b & 1) ? addi(tmp, a, m) : tmp;
}
long long power(long long a, long long b, long long m = mod) {
  long long tmp = 1;
  for (; b > 0; b >>= 1) {
    if (b & 1LL) tmp = mult(tmp, a, m);
    a = mult(a, a, m);
  }
  return tmp;
}
long long inv(long long a, long long m = mod) { return power(a, m - 2, m); }
long long n, m, k;
int d[N], trace[N], c[500][500], f[500][500], a[N], b[N];
bool visited[N];
vector<int> adj[N];
bool findpath() {
  fill(d, d + n * 2 + 2, -1);
  queue<int> q;
  q.push(0);
  d[0] = 0;
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    for (int v : adj[u]) {
      if (d[v] == -1 && c[u][v] > f[u][v]) {
        d[v] = d[u] + 1;
        trace[v] = u;
        q.push(v);
      }
    }
  }
  return d[n * 2 + 1] != -1;
}
int incflow(int x, int delta) {
  if (x == n * 2 + 1) return delta;
  visited[x] = true;
  for (int y : adj[x])
    if (d[y] == d[x] + 1 && trace[y] == x && c[x][y] > f[x][y]) {
      int tmp = incflow(y, min(delta, c[x][y] - f[x][y]));
      if (tmp != 0) {
        f[x][y] += tmp;
        f[y][x] -= tmp;
        return tmp;
      }
    }
  return 0;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  for (int i = 1; i <= n; ++i) cin >> a[i];
  for (int i = 1; i <= n; ++i) cin >> b[i];
  for (int i = 1; i <= n; ++i) {
    adj[0].push_back(i);
    adj[i].push_back(0);
    c[0][i] = a[i];
  }
  for (int i = 1; i <= n; ++i) {
    adj[i].push_back(i + n);
    adj[i + n].push_back(i);
    c[i][i + n] = 1e9;
  }
  for (int i = 1; i <= n; ++i) {
    adj[i + n].push_back(n * 2 + 1);
    adj[n * 2 + 1].push_back(i + n);
    c[i + n][n * 2 + 1] = b[i];
  }
  while (m--) {
    int u, v;
    cin >> u >> v;
    adj[u].push_back(v + n);
    adj[v + n].push_back(u);
    c[u][v + n] = 1e9;
    adj[v].push_back(u + n);
    adj[u + n].push_back(v);
    c[v][u + n] = 1e9;
  }
  int res = 0;
  while (findpath()) {
    fill(visited, visited + n * 2 + 2, false);
    res += incflow(0, 1e9);
  }
  int cnt1 = 0, cnt2 = 0;
  for (int i = 1; i <= n; ++i) {
    cnt1 += a[i];
    cnt2 += b[i];
  }
  if (res == cnt1 && cnt1 == cnt2) {
    cout << "YES\n";
    for (int i = 1; i <= n; ++i) {
      for (int j = 1; j <= n; ++j) {
        cout << f[i][j + n] << " \n"[j == n];
      }
    }
  } else
    cout << "NO\n";
  return 0;
}
