#include <bits/stdc++.h>
using namespace std;
const int sigma_size = 26;
const int N = 200 + 50;
const int MAXN = 100000 + 50;
const int inf = 0x3fffffff;
const double eps = 1e-8;
const int HASH = 100007;
const int mod = 1000000000 + 7;
int edge_cnt = 0;
int head[N], cur[N], d[N];
struct Edge {
  int u, v, cap, flow, next;
} edge[MAXN << 1];
void init() {
  edge_cnt = 0;
  memset(head, -1, sizeof(head));
}
void addedge(int u, int v, int cap) {
  edge[edge_cnt].u = u;
  edge[edge_cnt].v = v;
  edge[edge_cnt].cap = cap;
  edge[edge_cnt].flow = 0;
  edge[edge_cnt].next = head[u];
  head[u] = edge_cnt++;
  edge[edge_cnt].u = v;
  edge[edge_cnt].v = u;
  edge[edge_cnt].cap = 0;
  edge[edge_cnt].flow = 0;
  edge[edge_cnt].next = head[v];
  head[v] = edge_cnt++;
}
bool bfs(int st, int ed) {
  queue<int> que;
  memset(d, -1, sizeof(d));
  d[st] = 0;
  que.push(st);
  while (!que.empty()) {
    int u = que.front();
    que.pop();
    for (int i = head[u]; i != -1; i = edge[i].next) {
      int v = edge[i].v;
      if (d[v] == -1 && edge[i].cap - edge[i].flow) {
        d[v] = d[u] + 1;
        if (v == ed) return true;
        que.push(v);
      }
    }
  }
  return false;
}
int dfs(int u, int ed, int low) {
  if (u == ed || low == 0) return low;
  int flow = 0, f;
  for (int &i = cur[u]; i != -1; i = edge[i].next) {
    int v = edge[i].v;
    if (d[v] == d[u] + 1 &&
        (f = dfs(v, ed, min(low, edge[i].cap - edge[i].flow))) > 0) {
      edge[i].flow += f;
      edge[i ^ 1].flow -= f;
      flow += f;
      low -= f;
      if (low == 0) break;
    }
  }
  return flow;
}
int dinic(int st, int ed) {
  int flow = 0;
  while (bfs(st, ed)) {
    memcpy(cur, head, sizeof(head));
    flow += dfs(st, ed, inf);
  }
  return flow;
}
int n, m;
int a[N], b[N];
int mp[N][N];
int main() {
  while (~scanf("%d%d", &n, &m)) {
    init();
    int sum = 0, sum1 = 0;
    for (int i = 0; i < n; i++) {
      scanf("%d", &a[i]);
      sum1 += a[i];
      addedge(0, i + 1, a[i]);
    }
    for (int i = 0; i < n; i++) {
      scanf("%d", &b[i]);
      sum += b[i];
      addedge(n + i + 1, 2 * n + 1, b[i]);
    }
    for (int i = 1; i <= n; i++) addedge(i, i + n, inf);
    for (int i = 0; i < m; i++) {
      int u, v;
      scanf("%d%d", &u, &v);
      addedge(u, v + n, inf);
      addedge(v, u + n, inf);
    }
    if (sum1 != sum) {
      printf("NO\n");
      continue;
    }
    int ans = dinic(0, 2 * n + 1);
    if (ans < sum) {
      printf("NO\n");
      continue;
    }
    printf("YES\n");
    for (int i = 4 * n; i < edge_cnt; i += 2) {
      int u = edge[i].u, v = edge[i].v;
      if (u <= n && v > n) mp[u][v - n] = edge[i].flow;
    }
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        if (j) printf(" ");
        printf("%d", mp[i + 1][j + 1]);
      }
      printf("\n");
    }
  }
  return 0;
}
