#include <bits/stdc++.h>
using namespace std;
const int INF = 0x7fffffff;
void read(int &val) {
  int x = 0;
  int bz = 1;
  char c;
  for (c = getchar(); (c < '0' || c > '9') && c != '-'; c = getchar())
    ;
  if (c == '-') {
    bz = -1;
    c = getchar();
  }
  for (; c >= '0' && c <= '9'; c = getchar()) x = x * 10 + c - 48;
  val = x * bz;
}
const int maxn = 1e3 + 10;
struct Edge {
  int to, Next, flow;
};
int a[maxn], b[maxn];
struct Dinic {
  int n, s, t, tot;
  bool vis[maxn];
  Edge edges[maxn * 6];
  int d[maxn], head[maxn * 6], q[maxn];
  void init(int _s, int _t, int _n) {
    s = _s;
    t = _t;
    n = _n;
    memset(head, -1, sizeof(head));
    tot = 0;
  }
  void addEdge(int u, int v, int flow) {
    edges[tot].to = v;
    edges[tot].flow = flow;
    edges[tot].Next = head[u];
    head[u] = tot++;
    edges[tot].to = u;
    edges[tot].flow = 0;
    edges[tot].Next = head[v];
    head[v] = tot++;
  }
  bool bfs() {
    memset(vis, 0, sizeof(vis));
    int l = 0, r = 0;
    q[r++] = s;
    d[s] = 0;
    vis[s] = 1;
    while (l < r) {
      int u = q[l++];
      for (int i = head[u]; ~i; i = edges[i].Next) {
        int to = edges[i].to;
        if (vis[to] == 0 && edges[i].flow > 0) {
          vis[to] = 1;
          d[to] = d[u] + 1;
          q[r++] = to;
        }
      }
    }
    return vis[t];
  }
  int dfs(int u, int a) {
    if (u == t || a == 0) return a;
    int flow = 0, f;
    for (int i = head[u]; ~i; i = edges[i].Next) {
      int to = edges[i].to;
      if (d[u] + 1 == d[to] && edges[i].flow > 0) {
        f = dfs(to, min(a - flow, edges[i].flow));
        edges[i].flow -= f;
        edges[i ^ 1].flow += f;
        flow += f;
        if (flow == a) return flow;
      }
    }
    if (flow == 0) d[u] = 0;
    return flow;
  }
  int max_flow() {
    int flow = 0;
    while (bfs()) {
      flow += dfs(s, INF);
    }
    return flow;
  }
  void print(int num) {
    for (int i = 1; i <= num; i++) {
      int cap[200];
      memset(cap, 0, sizeof(cap));
      for (int v = head[i]; ~v; v = edges[v].Next) {
        int to = edges[v].to;
        cap[to - num] = edges[v ^ 1].flow;
      }
      for (int i = 1; i <= num; i++) printf("%d ", cap[i]);
      printf("\n");
    }
  }
} g;
int main() {
  int n, m, u;
  read(n);
  read(m);
  int s = 0, t = n + n + 1;
  g.init(s, t, n + n + 2);
  int sum1 = 0, sum2 = 0;
  for (int i = 1; i <= n; i++) {
    read(a[i]);
    sum1 += a[i];
  }
  for (int i = 1; i <= n; i++) {
    read(b[i]);
    sum2 += b[i];
  }
  if (sum1 != sum2) {
    printf("NO\n");
    return 0;
  }
  for (int i = 1; i <= n; i++) g.addEdge(s, i, a[i]);
  for (int i = 1; i <= n; i++) g.addEdge(i + n, t, b[i]);
  for (int i = 1; i <= n; i++) g.addEdge(i, i + n, 1000);
  for (int i = 1; i <= m; i++) {
    int u, v;
    read(u);
    read(v);
    g.addEdge(u, v + n, 1000);
    g.addEdge(v, u + n, 1000);
  }
  if (g.max_flow() != sum1) {
    printf("NO\n");
    return 0;
  }
  printf("YES\n");
  g.print(n);
  return 0;
}
