#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1.0);
const double eps = 1e-6;
const int INF = 0x3f3f3f3f;
const int MAXN = 2e2 + 10;
int n, m, head[MAXN], cnt, S, T, w[MAXN], g[MAXN][MAXN];
struct Edge {
  int v, w, nex;
} edge[MAXN * MAXN];
void add(int u, int v, int w) {
  edge[cnt] = {v, w, head[u]};
  head[u] = cnt++;
  edge[cnt] = {u, 0, head[v]};
  head[v] = cnt++;
}
queue<int> q;
int d[MAXN], cur[MAXN];
int find(int u, int lim) {
  if (u == T) return lim;
  int flow = 0;
  for (int i = cur[u]; ~i && flow < lim; i = edge[i].nex) {
    int v = edge[i].v;
    cur[u] = i;
    if (d[v] == d[u] + 1 && edge[i].w) {
      int tmp = find(v, min(edge[i].w, lim - flow));
      if (!tmp) d[v] = -1;
      edge[i].w -= tmp;
      edge[i ^ 1].w += tmp;
      flow += tmp;
    }
  }
  return flow;
}
bool bfs() {
  memset(d, -1, sizeof d);
  while (!q.empty()) q.pop();
  q.push(S);
  d[S] = 0, cur[S] = head[S];
  while (q.size()) {
    int u = q.front();
    q.pop();
    for (int i = head[u]; ~i; i = edge[i].nex) {
      int v = edge[i].v;
      int w = edge[i].w;
      if (d[v] == -1 && w) {
        d[v] = d[u] + 1;
        cur[v] = head[v];
        if (v == T) return true;
        q.push(v);
      }
    }
  }
  return false;
}
int dinic() {
  int r = 0, flow;
  while (bfs())
    while (flow = find(S, INF)) r += flow;
  return r;
}
int main() {
  int tot = 0;
  int ret = 0;
  memset(head, -1, sizeof head);
  cin >> n >> m;
  S = 0, T = 2 * n + 1;
  for (int i = 1; i <= n; i++) {
    cin >> w[i];
    add(S, i, w[i]);
    add(i, n + i, w[i]);
    tot += w[i];
  }
  for (int i = 1; i <= n; i++) {
    int x;
    cin >> x;
    ret += x;
    add(i + n, T, x);
  }
  for (int i = 1; i <= m; i++) {
    int u, v;
    cin >> u >> v;
    add(u, n + v, INF);
    add(v, n + u, INF);
  }
  if (ret != tot) {
    puts("NO");
    return 0;
  }
  int tmp = dinic();
  if (tmp == tot) {
    puts("YES");
    for (int u = 1; u <= n; u++)
      for (int i = head[u]; ~i; i = edge[i].nex) {
        int v = edge[i].v;
        int w = edge[i ^ 1].w;
        if (v > n && v <= n + n) g[u][v - n] += w;
      }
    for (int i = 1; i <= n; i++) {
      for (int j = 1; j <= n; j++) cout << g[i][j] << " ";
      cout << endl;
    }
  } else
    puts("NO");
  return 0;
}
