#include <bits/stdc++.h>
using namespace std;
int p[305], cap[305][305], maxflow, n, mat[305][305], level[305], v[305];
vector<int> adj[305];
int bfs(int s, int t) {
  queue<int> q;
  int v;
  int i;
  level[s] = 0;
  q.push(s);
  while (!q.empty()) {
    v = q.front();
    q.pop();
    for (i = 0; i < adj[v].size(); i++) {
      if (level[adj[v][i]] == -1 && cap[v][adj[v][i]] > 0) {
        q.push(adj[v][i]);
        level[adj[v][i]] = level[v] + 1;
      }
    }
  }
  return level[t] == -1;
}
int dfs(int x, int t, int flow) {
  if (x == t) return flow;
  for (; v[x] < adj[x].size(); v[x]++) {
    if (level[adj[x][v[x]]] == level[x] + 1 && cap[x][adj[x][v[x]]] > 0) {
      int currflow = min(flow, cap[x][adj[x][v[x]]]);
      currflow = dfs(adj[x][v[x]], t, currflow);
      if (currflow) {
        cap[x][adj[x][v[x]]] -= currflow;
        cap[adj[x][v[x]]][x] += currflow;
        return currflow;
      }
    }
  }
  return 0;
}
void mflow(int s, int t) {
  while (1) {
    memset(level, -1, sizeof level);
    if (bfs(s, t)) break;
    memset(v, 0, sizeof v);
    while (int temp = dfs(s, t, 1000000000)) maxflow += temp;
  }
}
int main() {
  int i, e, j, a[305], b[305], suma = 0, sumb = 0;
  bool casodeborda = false;
  scanf("%d %d", &n, &e);
  for (i = 1; i <= n; i++) {
    scanf("%d", a + i);
    suma += a[i];
  }
  for (i = 1; i <= n; i++) {
    scanf("%d", b + i);
    sumb += b[i];
  }
  casodeborda = suma != sumb;
  for (i = 0; i < e; i++) {
    int x, y;
    scanf("%d %d", &x, &y);
    adj[x].push_back(y + n + 1);
    adj[y + n + 1].push_back(x);
    cap[x][y + n + 1] = 1000000000;
    adj[y].push_back(x + n + 1);
    adj[x + n + 1].push_back(y);
    cap[y][x + n + 1] = 1000000000;
  }
  for (i = 1; i <= n; i++) {
    adj[0].push_back(i);
    adj[i].push_back(0);
    cap[0][i] = a[i];
    adj[i].push_back(i + n + 1);
    cap[i][i + n + 1] = 1000000000;
    adj[i + n + 1].push_back(i);
    adj[i + n + 1].push_back(n + 1);
    cap[i + n + 1][n + 1] = b[i];
  }
  maxflow = 0;
  mflow(0, n + 1);
  for (i = 1; i <= n; i++) maxflow -= b[i];
  if (maxflow == 0 && !casodeborda) {
    printf("YES\n");
    for (i = 1; i <= n; i++) {
      for (j = 1; j <= n; j++)
        printf("%d ",
               1000000000 -
                   (cap[i][j + n + 1] == 0 ? 1000000000 : cap[i][j + n + 1]));
      printf("\n");
    }
  } else
    printf("NO\n");
  return 0;
}
