#include <bits/stdc++.h>
using namespace std;
const int MAXN = 300;
vector<int> adj[MAXN];
int radj[MAXN][MAXN];
int src, tgt;
int par[MAXN];
int auxans[MAXN][MAXN];
inline void add_edge(int u, int v, int cap) {
  adj[u].push_back(v);
  adj[v].push_back(u);
  radj[u][v] = cap;
  radj[v][u] = 0;
}
int get_cap_aug_path() {
  memset(par, -1, sizeof(par));
  queue<int> q;
  q.push(src);
  par[src] = src;
  while (!q.empty() && q.front() != tgt) {
    int u = q.front();
    q.pop();
    for (__typeof((adj[u]).begin()) it = (adj[u]).begin(); it != (adj[u]).end();
         ++it) {
      if (radj[u][*it] && par[*it] == -1) {
        par[*it] = u;
        q.push(*it);
      }
    }
  }
  if (par[tgt] == -1) return 0;
  int res_cap = 0x3f3f3f3f;
  int v = tgt;
  while (true) {
    int u = par[v];
    res_cap = min(res_cap, radj[u][v]);
    if (u == src) break;
    v = u;
  }
  v = tgt;
  while (true) {
    int u = par[v];
    radj[u][v] -= res_cap;
    radj[v][u] += res_cap;
    if (u == src) break;
    v = u;
  }
  return res_cap;
}
void prepare(int n) {
  for (int i = 0; i < (MAXN); ++i) adj[i].clear();
  src = 0;
  tgt = 2 * n + 1;
}
int get_max_flow() {
  int mflow = 0;
  int aux;
  while ((aux = get_cap_aug_path())) {
    mflow += aux;
  }
  return mflow;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  int n, m;
  while (cin >> n >> m) {
    prepare(n);
    int orflow = 0;
    for (int i = 0; i < (n); ++i) {
      int cap;
      cin >> cap;
      add_edge(src, i + 1, cap);
      add_edge(i + 1, n + i + 1, 0x3f3f3f3f);
      orflow += cap;
    }
    int tgtflow = 0;
    for (int i = 0; i < (n); ++i) {
      int cap;
      cin >> cap;
      add_edge(n + 1 + i, tgt, cap);
      tgtflow += cap;
    }
    while (m--) {
      int x, y;
      cin >> x >> y;
      --x;
      --y;
      add_edge(x + 1, y + n + 1, 0x3f3f3f3f);
      add_edge(y + 1, x + n + 1, 0x3f3f3f3f);
    }
    if (orflow != tgtflow || tgtflow != get_max_flow())
      cout << "NO\n";
    else {
      cout << "YES\n";
      memset(auxans, 0, sizeof(auxans));
      for (int i = 0; i < (n); ++i)
        for (__typeof((adj[i + 1]).begin()) it = (adj[i + 1]).begin();
             it != (adj[i + 1]).end(); ++it) {
          if (radj[*it][i + 1]) {
            auxans[i][*it - n - 1] = radj[*it][i + 1];
          }
        }
      for (int i = 0; i < (n); ++i) {
        for (int j = 0; j < (n); ++j) {
          if (j) cout << " ";
          cout << auxans[i][j];
        }
        cout << "\n";
      }
    }
  }
  return 0;
}
