#include <bits/stdc++.h>
using namespace std;
const int maxn = 222;
int Map[maxn][maxn];
int s;
int e;
int level[maxn];
const int INF = 0xfffffff;
int bfs() {
  memset(level, 0, sizeof(level));
  queue<int> q;
  q.push(s);
  level[s] = 1;
  while (!q.empty()) {
    int cur = q.front();
    q.pop();
    for (int i = 0; i <= e; i++) {
      if (Map[cur][i] && !level[i]) {
        level[i] = level[cur] + 1;
        q.push(i);
      }
    }
  }
  return level[e];
}
int dfs(int x, int val) {
  int tem = val;
  if (x == e) return val;
  for (int i = 0; i <= e && tem; i++) {
    if (Map[x][i] && level[i] == level[x] + 1) {
      int t = dfs(i, min(tem, Map[x][i]));
      Map[x][i] -= t;
      Map[i][x] += t;
      tem -= t;
    }
  }
  return val - tem;
}
int dinic() {
  int t;
  int ans = 0;
  while (bfs()) {
    while (t = dfs(s, INF)) {
      ans += t;
    }
  }
  return ans;
}
int a[maxn], b[maxn];
int main() {
  int n, m, c, d;
  int sum = 0;
  int sum1 = 0;
  scanf("%d%d", &n, &m);
  memset(Map, 0, sizeof(Map));
  for (int i = 0; i < n; i++) scanf("%d", &a[i]), sum += a[i];
  for (int i = 0; i < n; i++) scanf("%d", &b[i]), sum1 += b[i];
  s = 2 * n;
  e = 2 * n + 1;
  for (int i = 0; i < n; i++) Map[s][i] = a[i];
  for (int i = 0; i < n; i++) Map[i + n][e] = b[i];
  for (int i = 0; i < n; i++) Map[i][i + n] = INF;
  for (int i = 0; i < m; i++) {
    scanf("%d%d", &c, &d);
    c--;
    d--;
    Map[c][d + n] = INF;
    Map[d][c + n] = INF;
  }
  int sum3 = dinic();
  if (sum == sum1 && sum1 == sum3) {
    printf("YES\n");
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        if (Map[i][j + n] != INF && Map[i][j + n] != 0)
          printf("%d ", INF - Map[i][j + n]);
        else
          printf("0 ");
      }
      cout << endl;
    }
  } else
    printf("NO\n");
  return 0;
}
