#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const int maxn = 3e2 + 5;
long long int power(long long int base, long long int exp) {
  long long int res = 1;
  while (exp) {
    if (exp % 2) res *= base;
    base *= base;
    res %= mod;
    base %= mod;
    exp /= 2;
  }
  return res;
}
bool visit[maxn];
int adj[maxn][maxn], par[maxn], n, m, a[maxn], b[maxn];
bool bfs(int s, int t) {
  memset(visit, 0, sizeof(visit));
  queue<int> q;
  q.push(s);
  visit[s] = 1;
  par[s] = -1;
  while (!q.empty()) {
    int curr = q.front();
    q.pop();
    for (int i = 0; i <= 2 * n + 1; i++) {
      if (!visit[i] && adj[curr][i]) {
        q.push(i);
        par[i] = curr;
        visit[i] = 1;
      }
    }
  }
  return visit[t];
}
int flow(int s, int t) {
  int res = 0;
  while (bfs(s, t)) {
    int curr = mod;
    for (int i = t; i != s; i = par[i]) {
      curr = min(curr, adj[par[i]][i]);
    }
    for (int i = t; i != s; i = par[i]) {
      adj[par[i]][i] -= curr;
      adj[i][par[i]] += curr;
    }
    res += curr;
  }
  return res;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int u, v, i, j;
  cin >> n >> m;
  int s = 0, t = 2 * n + 1;
  int sum1 = 0, sum2 = 0, sum3 = 0;
  for (i = 1; i <= n; i++) {
    cin >> a[i];
    adj[0][i] = a[i];
    sum1 += a[i];
    adj[i][i + n] = mod;
  }
  for (i = 1; i <= n; i++) {
    cin >> b[i];
    adj[i + n][2 * n + 1] = b[i];
    sum2 += b[i];
  }
  for (i = 1; i <= m; i++) {
    cin >> u >> v;
    adj[u][v + n] = mod;
    adj[v][u + n] = mod;
  }
  sum3 = flow(s, t);
  if (sum1 == sum2 && sum2 == sum3) {
    cout << "YES"
         << "\n";
    for (i = 1; i <= n; i++) {
      for (j = 1; j <= n; j++) {
        cout << adj[j + n][i] << " ";
      }
      cout << "\n";
    }
  } else {
    cout << "NO";
  }
  return 0;
}
