#include <bits/stdc++.h>
using namespace std;
const long long INF = ~0ull >> 2;
const int Inf = 0x3f3f3f3f;
const int maxn = 1e3 + 5;
int Map[105][105];
int head[maxn], cur[maxn];
int lev[maxn];
int t;
int S = 0, T;
struct tagedge {
  int from, to, cap, next;
} edge[maxn * 2];
void AddEdge(int u, int v, int w) {
  edge[t].from = u;
  edge[t].to = v;
  edge[t].cap = w;
  edge[t].next = head[u];
  head[u] = t++;
  return;
}
bool LevelGraph() {
  queue<int> q;
  fill(lev, lev + maxn, -1);
  lev[S] = 0;
  q.push(S);
  while (!q.empty()) {
    int k = q.front();
    q.pop();
    for (int i = head[k]; i != -1; i = edge[i].next) {
      int v = edge[i].to;
      if (lev[v] == -1 && edge[i].cap > 0) {
        lev[v] = lev[k] + 1;
        q.push(v);
      }
    }
  }
  if (lev[T] == -1)
    return false;
  else
    return true;
}
int FindPath(int k, int flow_in) {
  if (k == T) return flow_in;
  int flow_out = 0;
  for (int i = cur[k]; i != -1; i = edge[i].next) {
    cur[k] = i;
    int v = edge[i].to;
    if (lev[v] == lev[k] + 1 && edge[i].cap > 0) {
      int flow = FindPath(v, min(flow_in, edge[i].cap));
      if (flow == 0) continue;
      flow_in -= flow;
      flow_out += flow;
      edge[i].cap -= flow;
      edge[i ^ 1].cap += flow;
      if (flow_in == 0) break;
    }
  }
  return flow_out;
}
int Dinic() {
  int res = 0;
  while (LevelGraph()) {
    memcpy(cur, head, sizeof(head));
    res += FindPath(S, Inf);
  }
  return res;
}
void init() {
  fill(head, head + maxn, -1);
  t = 0;
  return;
}
int main() {
  init();
  int n, m;
  int sum_a = 0, sum_b = 0;
  scanf("%d%d", &n, &m);
  T = 2 * n + 5;
  for (int i = 1; i <= n; i++) {
    int a;
    scanf("%d", &a);
    sum_a += a;
    AddEdge(S, i, a);
    AddEdge(i, S, 0);
    AddEdge(i, n + i, Inf);
    AddEdge(n + i, i, 0);
  }
  for (int i = 1; i <= n; i++) {
    int b;
    scanf("%d", &b);
    sum_b += b;
    AddEdge(n + i, T, b);
    AddEdge(T, n + i, 0);
  }
  while (m--) {
    int u, v;
    scanf("%d%d", &u, &v);
    AddEdge(u, n + v, Inf);
    AddEdge(n + v, u, 0);
    AddEdge(v, n + u, Inf);
    AddEdge(n + u, v, 0);
  }
  if (sum_a != sum_b)
    cout << "NO";
  else {
    int res = Dinic();
    if (res != sum_a) {
      cout << "NO";
    } else {
      for (int k = 1; k <= n; k++) {
        for (int i = head[k]; i != -1; i = edge[i].next) {
          int v = edge[i].to;
          if (v != S) {
            Map[k][v - n] = Inf - edge[i].cap;
          }
        }
      }
      cout << "YES" << endl;
      for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= n; j++) {
          printf("%d ", Map[i][j]);
        }
        printf("\n");
      }
    }
  }
  return 0;
}
