#include <bits/stdc++.h>
using namespace std;
const int N = 2e3 + 2;
struct Edge {
  int v, c;
  Edge(int v, int c) : v(v), c(c) {}
};
vector<Edge> E;
vector<int> g[N];
void addEdge(int u, int v, int c) {
  g[u].push_back(E.size());
  E.push_back({v, c});
  g[v].push_back(E.size());
  E.push_back({u, 0});
}
int d[N];
int n, m;
int s, t;
int bfs() {
  fill(d, d + 1 + n, -1);
  d[s] = 0;
  queue<int> q;
  q.push(s);
  while (q.size()) {
    int u = q.front();
    q.pop();
    for (int i : g[u]) {
      int C = E[i].c;
      if (E[i].c == 0) continue;
      int z = E[i].v;
      if (d[z] < 0) {
        d[z] = d[u] + 1;
        q.push(z);
      }
    }
  }
  return d[t] >= 0;
}
int dfs(int u, int F) {
  if (u == t || F == 0) return F;
  for (int i : g[u]) {
    if (E[i].c == 0) continue;
    int v = E[i].v;
    if (d[v] != d[u] + 1) continue;
    int res = dfs(v, min(F, E[i].c));
    if (res) {
      E[i].c -= res;
      i ^= 1;
      E[i].c += res;
      return res;
    }
  }
  return 0;
}
int MaxFlow() {
  int ans = 0;
  while (bfs())
    while (int cur = dfs(s, 10000)) ans += cur;
  return ans;
}
int a[N][N];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin.tie(0);
  cin >> n >> m;
  s = 0;
  t = n + n + 1;
  int Sum1 = 0;
  int Sum2 = 0;
  for (int i = 1; i < t; ++i) {
    int x;
    cin >> x;
    if (i <= n)
      addEdge(s, i, x), Sum1 += x;
    else
      addEdge(i, t, x), Sum2 += x;
  }
  for (int i = 1; i <= n; ++i) addEdge(i, i + n, 100);
  while (m--) {
    int x;
    cin >> x;
    int y;
    cin >> y;
    addEdge(x, y + n, 100);
    addEdge(y, x + n, 100);
  }
  n = t;
  if (Sum1 != Sum2) return 0 * puts("NO");
  if (Sum1 != MaxFlow()) return 0 * puts("NO");
  cout << "YES\n";
  n /= 2;
  for (int i = 1; i <= n; ++i)
    for (int j : g[i + n])
      if (j & 1) a[E[j].v][i] = E[j].c;
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= n; ++j) cout << a[i][j] << (j == n ? "\n" : " ");
}
