#include <bits/stdc++.h>
using namespace std;
const int V = 210;
int graph[V][V] = {0}, f, m;
int p[V];
void augment(int v, int minEdge, int st) {
  if (v == st) {
    f = minEdge;
    return;
  } else if (p[v] != -1) {
    augment(p[v], min(minEdge, graph[p[v]][v]), st);
    graph[p[v]][v] -= f;
    graph[v][p[v]] += f;
  }
}
int dist[210];
int max_flow(int s, int t) {
  int mf = 0;
  while (1) {
    f = 0;
    for (int i = 0; i <= m; i++) {
      dist[i] = (0x7fffffff);
      p[i] = -1;
    }
    dist[s] = 0;
    queue<int> q;
    q.push(s);
    while (!q.empty()) {
      int u = q.front();
      q.pop();
      if (u == t) break;
      for (int v = 0; v <= m; v++) {
        if (graph[u][v] > 0 && dist[v] == (0x7fffffff)) {
          dist[v] = dist[u] + 1;
          q.push(v);
          p[v] = u;
        }
      }
    }
    augment(t, (0x7fffffff), s);
    if (f == 0) break;
    mf += f;
  }
  return mf;
}
int a[101], b[101];
int main() {
  ios::sync_with_stdio(false);
  int n, ed;
  cin >> n >> ed;
  int suma = 0, sumb = 0;
  for (int i = 1; i < n + 1; i++) {
    cin >> a[i];
    suma += a[i];
  }
  for (int i = 1; i < n + 1; i++) {
    cin >> b[i];
    sumb += b[i];
  }
  m = 2 * n + 1;
  for (int i = 1; i < n + 1; i++) {
    graph[0][i] = a[i];
    graph[n + i][2 * n + 1] = b[i];
    graph[i][n + i] = (0x7fffffff);
  }
  int x, y;
  while (ed--) {
    cin >> x >> y;
    graph[x][n + y] = (0x7fffffff);
    graph[y][n + x] = (0x7fffffff);
  }
  int maxflow = max_flow(0, 2 * n + 1);
  if (maxflow != suma || maxflow != sumb)
    cout << "NO";
  else {
    cout << "YES\n";
    for (int i = 1; i <= n; i++) {
      for (int j = n + 1; j <= 2 * n; j++) {
        if (graph[i][j] <= 0)
          cout << 0;
        else
          cout << (0x7fffffff) - graph[i][j];
        cout << " ";
      }
      cout << endl;
    }
  }
  return 0;
}
