#include <bits/stdc++.h>
using namespace std;
const int MAX = 210;
const int INF = 300;
vector<int> adj[MAX];
int previ[MAX], res[MAX][MAX], m[MAX];
int N;
int in[MAX];
int out[MAX];
void init(int n) {
  for (int i = (0); i < (n); i++) adj[i].clear();
  for (int i = (0); i < (n); i++)
    for (int j = (0); j < (n); j++) res[i][j] = 0;
}
void add(int u, int v, int cost) {
  adj[u].push_back(v);
  adj[v].push_back(u);
  res[u][v] += cost;
}
bool augment(int s, int t) {
  memset(previ, -1, sizeof previ);
  queue<int> Q;
  Q.push(s);
  previ[s] = -2;
  m[s] = INF;
  while (!Q.empty()) {
    int u = Q.front();
    Q.pop();
    if (u == t) break;
    for (int i = (0); i < (adj[u].size()); i++) {
      int v = adj[u][i];
      if (res[u][v] > 0 and previ[v] == -1) {
        previ[v] = u;
        Q.push(v);
        m[v] = min(m[u], res[u][v]);
      }
    }
  }
  return (previ[t] != -1);
}
int MaxFlow(int s, int t) {
  int ans = 0, u, v;
  while (augment(s, t)) {
    u = t;
    while (u != s) {
      v = previ[u];
      res[v][u] -= m[t];
      res[u][v] += m[t];
      u = v;
    }
    ans += m[t];
  }
  return ans;
}
int main() {
  ios::sync_with_stdio(false);
  int E;
  cin >> N >> E;
  init(2 * N + 1);
  int s = 0, t = 2 * N + 1, v, w;
  int A = 0;
  int B = 0;
  for (int i = (0); i < (N); i++) {
    cin >> v;
    add(0, i + 1, v);
    A += v;
    add(i + 1, N + i + 1, INF);
  }
  for (int i = (0); i < (N); i++) {
    cin >> v;
    add(N + i + 1, 2 * N + 1, v);
    B += v;
  }
  for (int i = (0); i < (E); i++) {
    cin >> v >> w;
    add(v, N + w, INF);
    add(w, N + v, INF);
  }
  if (A != B)
    cout << "NO" << endl;
  else {
    B = MaxFlow(s, t);
    if (A != B)
      cout << "NO" << endl;
    else {
      cout << "YES" << endl;
      for (int i = (1); i < (N + 1); i++) {
        for (int j = (N + 1); j < (t); j++) {
          if (res[i][j] <= INF and res[i][j] != 0)
            cout << INF - res[i][j] << " ";
          else
            cout << "0 ";
        }
        cout << endl;
      }
    }
  }
}
