#include <bits/stdc++.h>
using namespace std;
inline void setmin(int &x, int y) {
  if (y < x) x = y;
}
inline void setmax(int &x, int y) {
  if (y > x) x = y;
}
inline void setmin(long long &x, long long y) {
  if (y < x) x = y;
}
inline void setmax(long long &x, long long y) {
  if (y > x) x = y;
}
const int N = 202;
const int inf = (int)1e9 + 1;
const long long big = (long long)1e18 + 1;
const int P = 239;
const int MOD = (int)1e9 + 7;
const int MOD1 = 998244353;
const double eps = 1e-14;
const double pi = atan2(0, -1);
const int ABC = 26;
int a[N], b[N];
vector<int> g[N];
bool used[N];
int pos[N];
int c[N][N], f[N][N];
int S, T;
int D;
int d[N];
int dfs(int u, int flow) {
  used[u] = true;
  if (u == T) return flow;
  for (; pos[u] < (int)g[u].size(); pos[u]++) {
    int v = g[u][pos[u]];
    if (c[u][v] - f[u][v] >= (1 << D) && d[v] == d[u] + 1) {
      int x = dfs(v, min(flow, c[u][v] - f[u][v]));
      if (x > 0) {
        f[u][v] += x;
        f[v][u] -= x;
        return x;
      }
    }
  }
  return 0;
}
bool bfs(int n) {
  fill(d, d + n, inf);
  d[S] = 0;
  queue<int> q;
  q.push(S);
  while ((int)q.size() > 0) {
    int u = q.front();
    q.pop();
    for (int v : g[u])
      if (c[u][v] - f[u][v] >= (1 << D) && d[v] == inf) {
        d[v] = d[u] + 1;
        q.push(v);
      }
  }
  return d[T] < inf;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.precision(20);
  cout << fixed;
  int n, m;
  cin >> n >> m;
  S = n * 2;
  T = S + 1;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    g[S].push_back(i);
    g[i].push_back(S);
    c[S][i] = a[i];
  }
  for (int i = 0; i < n; i++) {
    cin >> b[i];
    g[n + i].push_back(T);
    g[T].push_back(n + i);
    c[n + i][T] = b[i];
  }
  for (int i = 0; i < n; i++) {
    g[i].push_back(n + i);
    g[n + i].push_back(i);
    c[i][n + i] = inf;
  }
  for (int i = 0; i < m; i++) {
    int u, v;
    cin >> u >> v;
    u--;
    v--;
    g[u].push_back(n + v);
    g[n + v].push_back(u);
    c[u][n + v] = inf;
    g[v].push_back(n + u);
    g[n + u].push_back(v);
    c[v][n + u] = inf;
  }
  for (D = 7; D >= 0; D--)
    while (bfs(n * 2 + 2)) {
      fill(pos, pos + n * 2 + 2, 0);
      while (true) {
        fill(used, used + n, false);
        int x = dfs(S, inf);
        if (x == 0) break;
      }
    }
  int suma = 0, sumb = 0, sum = 0;
  for (int i = 0; i < n; i++) {
    suma += a[i];
    sumb += b[i];
  }
  for (int i = 0; i < n * 2 + 2; i++) sum += f[S][i];
  if (sum == suma && sum == sumb) {
    cout << "YES\n";
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) cout << f[i][n + j] << " ";
      cout << "\n";
    }
  } else {
    cout << "NO\n";
  }
  return 0;
}
