#include <bits/stdc++.h>
using namespace std;
const int MAXN = 109, MAXM = 209;
const int INF = 0x3f3f3f3f;
int n, m;
struct Net {
  int size;
  int head[MAXN * 2];
  int to[MAXM * 4 + MAXN * 6];
  int cap[MAXM * 4 + MAXN * 6], f[MAXM * 4 + MAXN * 6];
  int ne[MAXM * 4 + MAXN * 6];
  Net() { size = 1; }
  void add_edge(int u, int v, int c) {
    to[size] = v, cap[size] = f[size] = c, ne[size] = head[u], head[u] = size++;
    to[size] = u, cap[size] = f[size] = 0, ne[size] = head[v], head[v] = size++;
  }
} G;
int s, t;
int suma, sumb;
int g[MAXN][MAXN];
int dis[MAXN * 2];
bool bfs(int s, int t) {
  queue<int> q;
  memset(dis, INF, sizeof(dis));
  q.push(t), dis[t] = 0;
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    for (int i = G.head[u]; i; i = G.ne[i]) {
      int v = G.to[i];
      if (G.f[(((i - 1) ^ 1) + 1)] && dis[v] > dis[u] + 1) {
        dis[v] = dis[u] + 1;
        q.push(v);
      }
    }
  }
  return dis[s] < INF;
}
int dfs(int u, int end, int flow) {
  if (u == end || !flow) return flow;
  int ret = 0, tmp;
  for (int i = G.head[u]; i; i = G.ne[i]) {
    int v = G.to[i];
    if (dis[v] == dis[u] - 1 && G.f[i] &&
        (tmp = dfs(v, end, min(flow, G.f[i])))) {
      G.f[i] -= tmp, G.f[(((i - 1) ^ 1) + 1)] += tmp;
      ret += tmp, flow -= tmp;
      if (!flow) break;
    }
  }
  if (!flow) dis[u] = INF;
  return ret;
}
int dinic(int s, int t, int flow) {
  int ret = 0;
  while (bfs(s, t)) ret += dfs(s, t, flow);
  return ret;
}
int main() {
  scanf("%d%d", &n, &m);
  s = (n << 1) + 1, t = s + 1;
  for (int i = 1, x; i <= n; ++i) {
    scanf("%d", &x);
    G.add_edge(s, ((i)*2 - 1), x);
    suma += x;
  }
  for (int i = 1, x; i <= n; ++i) {
    scanf("%d", &x);
    G.add_edge(((i)*2), t, x);
    sumb += x;
  }
  for (int i = 1; i <= m; ++i) {
    int u, v;
    scanf("%d%d", &u, &v);
    G.add_edge(((u)*2 - 1), ((v)*2), INF);
    G.add_edge(((v)*2 - 1), ((u)*2), INF);
  }
  for (int i = 1; i <= n; ++i) G.add_edge(((i)*2 - 1), ((i)*2), INF);
  int maxflow = dinic(s, t, INF);
  if (maxflow != suma || maxflow != sumb) {
    puts("NO");
    return 0;
  }
  for (int i = 1; i <= n; ++i)
    for (int j = G.head[((i)*2 - 1)]; j; j = G.ne[j])
      g[i][(G.to[j] + 1) >> 1] += G.cap[j] - G.f[j];
  puts("YES");
  for (int i = 1; i <= n; ++i) {
    printf("%d", g[i][1]);
    for (int j = 2; j <= n; ++j) printf(" %d", g[i][j]);
    puts("");
  }
  return 0;
}
