#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 1000;
const int oo = 1e8;
vector<int> v[MAX_N];
int res[MAX_N][MAX_N];
int par[MAX_N];
bool visited[MAX_N][MAX_N];
long long f;
int s, t;
void augment(int y = t, int minedge = oo) {
  if (y == s) {
    f = minedge;
    return;
  }
  if (par[y] != -1) {
    augment(par[y], min(minedge, res[par[y]][y]));
    if (!visited[y][par[y]]) {
      v[y].push_back(par[y]);
      visited[y][par[y]] = 1;
    }
    res[y][par[y]] += f;
    res[par[y]][y] -= f;
  }
}
long long max_flow = 0;
void Edmonds_karp() {
  bitset<MAX_N> visit;
  while (1) {
    visit.reset();
    memset(par, -1, sizeof par);
    queue<int> q;
    q.push(s);
    visit[s] = 1;
    while (!q.empty()) {
      int u = q.front();
      q.pop();
      for (int i = 0; i < v[u].size(); i++) {
        int ve = v[u][i];
        if (res[u][ve] > 0 && !visit[ve])
          visit[ve] = 1, par[ve] = u, q.push(ve);
      }
    }
    f = 0;
    augment(t);
    if (f == 0) return;
    max_flow += f;
  }
}
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 0; i <= 2 * n + 1; i++)
    for (int j = 0; j <= 2 * n + 1; j++) visited[i][j] = 0;
  s = 0;
  t = 2 * n + 1;
  int x;
  int sum1 = 0, sum2 = 0;
  for (int i = 1; i <= n; i++) {
    v[s].push_back(i);
    visited[s][i] = 1;
    cin >> x;
    sum1 += x;
    res[s][i] = x;
  }
  for (int i = n + 1; i <= 2 * n; i++) {
    v[i].push_back(t);
    cin >> x;
    sum2 += x;
    visited[i][t] = 1;
    res[i][t] = x;
  }
  for (int i = 1; i <= n; i++) {
    visited[i][i + n] = 1;
    res[i][i + n] = oo;
    v[i].push_back(i + n);
  }
  int xx, yy;
  for (int i = 0; i < m; i++) {
    cin >> xx >> yy;
    visited[xx][n + yy];
    visited[yy][n + xx];
    res[xx][n + yy] = oo;
    v[xx].push_back(n + yy);
    res[yy][n + xx] = oo;
    v[yy].push_back(xx + n);
  }
  Edmonds_karp();
  if (max_flow == sum1 && max_flow == sum2) {
    cout << "YES" << endl;
    for (int i = 1; i <= n; i++) {
      for (int j = 1; j <= n; j++) cout << res[j + n][i] << " ";
      cout << endl;
    }
  } else
    cout << "NO" << endl;
}
