#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:102400000,102400000")
using namespace std;
const int inf = 2e9;
int ans[208][208];
int n, m;
namespace MaxFlow {
struct Edge {
  int to, capacity, revid;
  Edge() : to(-1), capacity(0), revid(-1){};
  Edge(int t, int c, int r) : to(t), capacity(c), revid(r) {}
};
int depth[34010];
size_t curr[34010];
vector<Edge> g[34010];
void buildEdge(int src, int dst, int cap) {
  g[src].push_back(Edge(dst, cap, int(g[dst].size())));
  g[dst].push_back(Edge(src, 0, int(g[src].size()) - 1));
}
void bfs(int src) {
  for (int i = 0; i <= 24000; i++) depth[i] = inf;
  queue<int> q;
  q.push(src);
  depth[src] = 0;
  while (!q.empty()) {
    int p = q.front();
    q.pop();
    for (size_t i = 0; i < g[p].size(); i++) {
      if (g[p][i].capacity == 0 || depth[g[p][i].to] <= depth[p] + 1) continue;
      q.push(g[p][i].to);
      depth[g[p][i].to] = depth[p] + 1;
    }
  }
}
int dfs(int x, int dst, int cmin) {
  if (x == dst) return cmin;
  for (size_t& i = curr[x]; i < g[x].size(); i++) {
    Edge& e = g[x][i];
    if (e.capacity == 0 || depth[e.to] <= depth[x]) continue;
    int d = dfs(e.to, dst, min(cmin, e.capacity));
    if (d > 0) {
      e.capacity -= d;
      int ac = x, ak = e.to;
      if (ac > n) ans[ak][ac - n] -= d;
      if (ak > n) ans[ac][ak - n] += d;
      g[e.to][e.revid].capacity += d;
      return d;
    }
  }
  return 0;
}
int solve(int src, int dst) {
  int res = 0;
  while (true) {
    bfs(src);
    if (depth[dst] == inf) return res;
    memset(curr, 0, sizeof curr);
    int d = dfs(src, dst, inf);
    while (d > 0) {
      res += d;
      d = dfs(src, dst, inf);
    }
  }
}
}  // namespace MaxFlow
int pep[108];
int pur[108];
int tot;
int main() {
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    cin >> pep[i];
    MaxFlow::buildEdge(i, n + i, inf);
    MaxFlow::buildEdge(0, i, pep[i]);
    tot += pep[i];
  }
  int sum = 0;
  for (int i = 1; i <= n; i++) {
    cin >> pur[i];
    sum += pur[i];
    MaxFlow::buildEdge(i + n, 205, pur[i]);
  }
  while (m--) {
    int a, b;
    cin >> a >> b;
    MaxFlow::buildEdge(a, b + n, inf);
    MaxFlow::buildEdge(b, a + n, inf);
  }
  if (MaxFlow::solve(0, 205) != tot or tot != sum) {
    cout << "NO";
    return 0;
  }
  puts("YES");
  cout << "";
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      printf("%d ", ans[i][j]);
    }
    puts("");
  }
}
