#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1.0);
const double eps = 1e-8;
const int mod = 1e9 + 7;
const int inf = 1061109567;
const int dir[][2] = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}};
const int maxn = 2e5;
int q[maxn * 2], head[maxn * 2], dis[maxn / 10], s, t, num, vis[105],
    val[205][205];
struct node {
  int to, nextt, c;
  node() {}
  node(int to, int nextt, int c) : to(to), nextt(nextt), c(c) {}
} e[maxn * 2];
void init() {
  num = 0;
  memset(head, -1, sizeof(head));
}
void add(int u, int v, int c) {
  e[num] = node(v, head[u], c);
  head[u] = num++;
  e[num] = node(u, head[v], 0);
  head[v] = num++;
}
int bfs() {
  memset(dis, 0, sizeof(dis));
  dis[s] = 1;
  int st = 0, ed = 0;
  q[ed++] = s;
  while (st < ed) {
    int u = q[st++];
    for (int i = head[u]; ~i; i = e[i].nextt) {
      int v = e[i].to;
      if (!dis[v] && e[i].c) {
        dis[v] = dis[u] + 1;
        if (v == t) return 1;
        q[ed++] = v;
      }
    }
  }
  return 0;
}
int dfs(int u, int limit) {
  if (u == t) {
    return limit;
  }
  int cost = 0;
  for (int i = head[u]; ~i; i = e[i].nextt) {
    int v = e[i].to;
    if (e[i].c && dis[v] == dis[u] + 1) {
      int tmp = dfs(v, min(limit - cost, e[i].c));
      if (tmp > 0) {
        e[i].c -= tmp;
        e[i ^ 1].c += tmp;
        cost += tmp;
        if (cost == limit) break;
      } else {
        dis[v] = -1;
      }
    }
  }
  return cost;
}
int dinic() {
  int ans = 0;
  while (bfs()) {
    ans += dfs(s, inf);
  }
  return ans;
}
int main() {
  int n, m, x, y, sum = 0, tmp = 0;
  cin >> n >> m;
  init();
  s = 0, t = n * 2 + 1;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &x);
    add(s, i, x);
    tmp += x;
  }
  for (int i = 1; i <= n; i++) {
    scanf("%d", &x);
    add(i + n, t, x);
    sum += x;
    add(i, i + n, inf);
  }
  while (m--) {
    scanf("%d%d", &x, &y);
    add(x, y + n, inf);
    add(y, x + n, inf);
  }
  int ans = dinic();
  if (ans != sum || sum != tmp) {
    cout << "NO" << endl;
    return 0;
  }
  cout << "YES" << endl;
  for (int u = 1; u <= n; u++) {
    for (int i = head[u]; ~i; i = e[i].nextt) {
      int v = e[i].to;
      if (v > n) {
        val[u][v - n] = e[i ^ 1].c;
      }
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      cout << val[i][j] << " ";
    }
    cout << endl;
  }
  return 0;
}
