#include <bits/stdc++.h>
using namespace std;
int n, m, a, b, val, ans, sum1, sum2, cap[205][205], pre[205], dis[205],
    flow[205][205];
vector<int> v[205];
struct node {
  int ind;
  int len;
  int minf;
  int before;
};
priority_queue<node> q;
bool operator<(const node& x, const node& y) {
  if (x.len != y.len) return x.len < y.len;
  return x.minf > y.minf;
}
int bfs() {
  int ret = 0;
  while (!q.empty()) q.pop();
  for (int i = 0; i <= n * 2 + 1; i++) dis[i] = 0;
  int s = v[0].size();
  for (int i = 0; i < s; i++)
    if (cap[0][v[0][i]]) {
      q.push((node){v[0][i], 1, cap[0][v[0][i]], 0});
      dis[v[0][i]] = 1;
    }
  while (!q.empty()) {
    node cur = q.top();
    q.pop();
    int u = cur.ind;
    if (dis[u] < cur.len) continue;
    pre[u] = cur.before;
    if (u == n * 2 + 1) {
      ans += cur.minf;
      int na = pre[u];
      int nb = u;
      while (nb != 0) {
        cap[na][nb] -= cur.minf;
        cap[nb][na] += cur.minf;
        flow[na][nb] += cur.minf;
        nb = na;
        na = pre[na];
      }
      ret = 1;
      break;
    }
    int s = v[u].size();
    for (int i = 0; i < s; i++) {
      int tar = v[u][i];
      if ((!dis[tar] || dis[tar] > cur.len + 1) && cap[u][tar]) {
        q.push((node){tar, cur.len + 1, min(cur.minf, cap[u][tar]), u});
        dis[tar] = cur.len + 1;
      }
    }
  }
  return ret;
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &val);
    v[0].push_back(i);
    cap[0][i] = val;
    sum1 += val;
  }
  for (int i = 1; i <= n; i++) {
    scanf("%d", &val);
    v[n + i].push_back(n * 2 + 1);
    cap[n + i][n * 2 + 1] = val;
    sum2 += val;
  }
  if (sum1 != sum2) {
    printf("NO\n");
    return 0;
  }
  for (int i = 1; i <= n; i++) {
    v[i].push_back(n + i);
    v[n + i].push_back(i);
    cap[i][n + i] = 10000;
  }
  for (int i = 0; i < m; i++) {
    scanf("%d%d", &a, &b);
    v[a].push_back(n + b);
    v[n + b].push_back(a);
    v[b].push_back(n + a);
    v[n + a].push_back(b);
    cap[a][n + b] = cap[b][n + a] = 10000;
  }
  while (bfs())
    ;
  if (ans != sum1)
    printf("NO\n");
  else {
    printf("YES\n");
    for (int i = 1; i <= n; i++) {
      for (int j = 1; j < n; j++)
        printf("%d ", flow[i][j + n] - flow[j + n][i]);
      printf("%d\n", flow[i][n * 2] - flow[n * 2][i]);
    }
  }
  return 0;
}
