#include <bits/stdc++.h>
using namespace std;
const int MAXN = 205;
int N, M;
int cap[MAXN][MAXN];
int res[MAXN][MAXN];
int flow[MAXN][MAXN];
int exc[MAXN];
int H[MAXN];
bool vis[MAXN];
void preflow(int source, int sink) {
  memset(H, 0, sizeof(H));
  H[source] = 2 * N + 2;
  memset(exc, 0, sizeof(exc));
  memset(flow, 0, sizeof(flow));
  memcpy(res, cap, sizeof(cap));
  for (int i = 0; i <= 2 * N + 1; i++)
    if (cap[source][i] != 0) {
      flow[source][i] = cap[source][i];
      flow[i][source] = -cap[source][i];
      exc[i] = cap[source][i];
      exc[source] -= cap[source][i];
      res[source][i] = cap[source][i] - flow[source][i];
      res[i][source] = cap[i][source] - flow[i][source];
    }
}
void push(int a, int b) {
  int f = min(exc[a], res[a][b]);
  flow[a][b] += f;
  flow[b][a] = -flow[a][b];
  exc[a] -= f;
  exc[b] += f;
  res[a][b] = cap[a][b] - flow[a][b];
  res[b][a] = cap[b][a] - flow[b][a];
}
void maxflow(int source, int sink) {
  preflow(source, sink);
  queue<int> q;
  memset(vis, 0, sizeof(vis));
  for (int i = 0; i <= 2 * N + 1; i++)
    if (cap[source][i] != 0 && i != sink) {
      vis[i] = true;
      q.push(i);
    }
  while (!q.empty()) {
    int cur = q.front(), h = -1;
    for (int i = 0; i <= 2 * N + 1 && exc[cur] > 0; i++)
      if (res[cur][i] > 0) {
        if (H[cur] > H[i]) {
          push(cur, i);
          if (!vis[i] && i != source && i != sink) {
            vis[i] = true;
            q.push(i);
          }
        } else if (h == -1)
          h = H[i];
        else
          h = min(h, H[i]);
      }
    if (exc[cur] != 0)
      H[cur] = h + 1;
    else {
      vis[cur] = false;
      q.pop();
    }
  }
}
int main() {
  ios::sync_with_stdio(0);
  cin >> N >> M;
  int suma = 0;
  for (int i = 0, a; i < N; i++) {
    cin >> a;
    cap[2 * N][i] = a;
    suma += a;
  }
  int sumb = 0;
  for (int i = N, b; i < 2 * N; i++) {
    cin >> b;
    cap[i][2 * N + 1] = b;
    sumb += b;
  }
  for (int i = 0, a, b; i < M; i++) {
    cin >> a >> b;
    cap[a - 1][b - 1 + N] = 1 << 30;
    cap[b - 1][a - 1 + N] = 1 << 30;
  }
  for (int i = 0; i < N; i++) cap[i][i + N] = 1 << 30;
  maxflow(2 * N, 2 * N + 1);
  int F = 0;
  for (int i = 0; i < N; i++) F += flow[2 * N][i];
  if (F == suma && F == sumb) {
    cout << "YES\n";
    for (int i = 0; i < N; i++) {
      for (int j = 0; j < N; j++) cout << flow[i][j + N] << " ";
      cout << "\n";
    }
  } else
    cout << "NO\n";
  return 0;
}
