#include <bits/stdc++.h>
using namespace std;
int N, E;
int a[105], b[105];
int weight[205][205];
bool vis[205];
int suma = 0, sumb = 0;
int getFlow(int u, int sink, int cap) {
  if (u == sink) return cap;
  vis[u] = true;
  for (int v = 0; v <= sink; v++) {
    if (!vis[v] && weight[u][v] > 0) {
      int flow = getFlow(v, sink, min(cap, weight[u][v]));
      weight[u][v] -= flow;
      weight[v][u] += flow;
      if (flow > 0) return flow;
    }
  }
  return 0;
}
void buildGraph(int source, int sink) {
  for (int i = 1; i <= N; i++) {
    weight[source][i] = a[i];
    suma += a[i];
  }
  for (int i = 1; i <= N; i++) {
    weight[N + i][sink] = b[i];
    sumb += b[i];
  }
  for (int i = 1; i <= N; i++) {
    weight[i][i + N] = 1e9;
  }
}
int main() {
  ios_base ::sync_with_stdio(false);
  cin >> N >> E;
  for (int i = 1; i <= N; i++) cin >> a[i];
  for (int i = 1; i <= N; i++) cin >> b[i];
  buildGraph(0, 2 * N + 1);
  for (int i = 1; i <= E; i++) {
    int u, v;
    cin >> u >> v;
    weight[u][v + N] = 1e9;
    weight[v][u + N] = 1e9;
  }
  int maxFlow = 0, flow = -1;
  do {
    memset(vis, 0, sizeof(vis));
    flow = getFlow(0, 2 * N + 1, INT_MAX);
    maxFlow += flow;
  } while (flow > 0);
  if (maxFlow == suma && maxFlow == sumb) {
    cout << "YES" << endl;
    for (int u = 1; u <= N; u++) {
      for (int v = 1; v <= N; v++) {
        cout << weight[v + N][u] << " ";
      }
      cout << endl;
    }
  } else {
    cout << "NO" << endl;
  }
  return 0;
}
