#include <bits/stdc++.h>
using namespace std;
const int INF = (int)2e9;
const long long INFL = (long long)9e18;
const int MAXINT = ((~0) ^ (1 << 31));
const long long MAXLL = ((~0) ^ ((long long)1 << 63));
template <class T>
inline T pow2(T a) {
  return a * a;
}
template <class T>
inline bool mineq(T& a, T b) {
  return (a > b) ? (a = b, true) : false;
}
template <class T>
inline bool maxeq(T& a, T b) {
  return (a < b) ? (a = b, true) : false;
}
const long long INFF = INF;
struct MaxFlow {
  int n;
  vector<vector<long long> > g;
  vector<vector<long long> > fl;
  vector<bool> visited;
  MaxFlow(int _n) {
    n = _n;
    g.resize(n);
    fl.resize(n);
    for (int i = 0; i < (int)(n); i++) {
      g[i].resize(n, 0);
      fl[i].resize(n, 0);
    }
    visited.resize(n, 0);
  }
  void addEdge(int a, int b, long long f) {
    g[a][b] += f;
    fl[a][b] += f;
  }
  void AddEdge(int a, int b, long long f) { g[a][b] += f; }
  long long dfs(int v, int sink, long long lim) {
    if (visited[v]) return 0;
    if (v == sink) return lim;
    visited[v] = true;
    for (int i = 0; i < (int)(n); i++) {
      if (g[v][i]) {
        long long f = dfs(i, sink, min(lim, g[v][i]));
        if (f != 0) {
          AddEdge(v, i, -f);
          AddEdge(i, v, f);
          return f;
        }
      }
    }
    return 0;
  }
  long long maxFlow(int src, int sink) {
    long long f, ans = 0;
    for (int i = 0; i < (int)(n); i++) visited[i] = false;
    while ((f = dfs(src, sink, INFF))) {
      ans += f;
      for (int i = 0; i < (int)(n); i++) visited[i] = false;
    }
    for (int i = 0; i < (int)(n); i++) {
      for (int j = 0; j < (int)(n); j++) {
        fl[i][j] -= g[i][j];
      }
    }
    return ans;
  }
};
const int maxn = (int)222;
;
MaxFlow mf(maxn);
int a[maxn], b[maxn], n, m, asum, bsum, sum;
int in[maxn], out[maxn], src, sink, id;
int ans[maxn][maxn];
void Done() {
  cout << "NO";
  exit(0);
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> m;
  src = id++;
  sink = id++;
  for (int i = 1; i < (int)(n + 1); i++) {
    in[i] = id++;
    out[i] = id++;
  }
  for (int i = 1; i < (int)(n + 1); i++) {
    cin >> a[i];
    asum += a[i];
  }
  for (int i = 1; i < (int)(n + 1); i++) {
    cin >> b[i];
    bsum += b[i];
  }
  for (int i = 0; i < (int)(m); i++) {
    int a, b;
    cin >> a >> b;
    mf.addEdge(out[a], in[b], INF);
    mf.addEdge(out[b], in[a], INF);
  }
  if (asum != bsum) {
    Done();
  }
  for (int i = 1; i < (int)(n + 1); i++) {
    mf.addEdge(in[i], out[i], a[i]);
    if (b[i] - a[i] > 0) {
      mf.addEdge(in[i], sink, b[i] - a[i]);
      sum += b[i] - a[i];
    } else {
      mf.addEdge(src, in[i], a[i] - b[i]);
    }
  }
  if (mf.maxFlow(src, sink) != sum) Done();
  for (int i = 1; i < (int)(n + 1); i++) {
    for (int j = 1; j < (int)(n + 1); j++) {
      ans[i][j] = mf.fl[out[i]][in[j]];
    }
  }
  for (int i = 1; i < (int)(n + 1); i++) {
    int input = 0, output = 0;
    for (int j = 1; j < (int)(n + 1); j++) {
      input += mf.fl[out[j]][in[i]];
      if (i != j) output += mf.fl[out[i]][in[j]];
    }
    ans[i][i] = a[i] - output;
  }
  cout << "YES\n";
  for (int i = 1; i < (int)(n + 1); i++) {
    for (int j = 1; j < (int)(n + 1); j++) {
      cout << ans[i][j] << " ";
    }
    cout << endl;
  }
}
