#include <bits/stdc++.h>
using namespace std;
struct MaxFlow {
  static const int MAX_NODE = 1010;
  static const int MAX_EDGE = 10010;
  static const int INF = 0x03f3f3f3f;
  int head[MAX_NODE];
  int counter[MAX_NODE];
  int h[MAX_NODE];
  int dest[MAX_EDGE];
  int pre[MAX_EDGE];
  int limit[MAX_EDGE];
  int total_flow, now_edge;
  int source, sink;
  MaxFlow() : total_flow(0), source(0), sink(0) {
    memset(h, 0, sizeof(h));
    memset(counter, 0, sizeof(counter));
    memset(head, 0, sizeof(head));
    memset(pre, 0, sizeof(pre));
    now_edge = 1;
  }
  void set_source_sink(int source, int sink) {
    this->source = source;
    this->sink = sink;
  }
  void add_edge(int x, int y, int z, bool flag = true) {
    dest[++now_edge] = y;
    limit[now_edge] = z;
    pre[now_edge] = head[x];
    head[x] = now_edge;
    if (flag) {
      add_edge(y, x, 0, false);
    }
  }
  int shortest_augment_path(int x, int remain) {
    if (x == sink) {
      return remain;
    }
    int tmp_remain = remain, minh = sink - 1;
    for (int k = head[x]; k > 0; k = pre[k])
      if (limit[k] > 0) {
        int y = dest[k];
        if (h[x] == h[y] + 1) {
          int ret = shortest_augment_path(y, min(remain, limit[k]));
          remain -= ret;
          limit[k] -= ret;
          limit[k ^ 1] += ret;
          if (remain == 0 || h[source] >= sink) {
            return tmp_remain - remain;
          }
        }
        if (h[y] < minh) minh = h[y];
      }
    if (remain == tmp_remain) {
      if (--counter[h[x]] == 0) {
        h[source] = sink;
      }
      h[x] = minh + 1;
      ++counter[h[x]];
    }
    return tmp_remain - remain;
  }
  int run() {
    counter[0] = sink;
    total_flow = 0;
    while (h[source] < sink) {
      total_flow += shortest_augment_path(source, INF);
    }
    return total_flow;
  }
};
const int MAX = 210;
int a[MAX], b[MAX];
MaxFlow max_flow;
int g[MAX][MAX];
int main() {
  int n, m;
  cin >> n >> m;
  int source = 1;
  int sink = 2 * n + 2;
  int a_sum = 0, b_sum = 0;
  max_flow.set_source_sink(source, sink);
  for (int i = 1; i <= n; ++i) {
    cin >> a[i];
    max_flow.add_edge(source, i + 1, a[i]);
    a_sum += a[i];
  }
  for (int i = 1; i <= n; ++i) {
    cin >> b[i];
    max_flow.add_edge(n + i + 1, sink, b[i]);
    b_sum += b[i];
  }
  for (int i = 1; i <= n; ++i) {
    max_flow.add_edge(i + 1, n + i + 1, MaxFlow::INF);
  }
  for (int i = 1; i <= m; ++i) {
    int x, y;
    cin >> x >> y;
    x++;
    y++;
    max_flow.add_edge(x, n + y, MaxFlow::INF);
    max_flow.add_edge(y, n + x, MaxFlow::INF);
  }
  max_flow.run();
  if (a_sum != b_sum || max_flow.total_flow != b_sum) {
    cout << "NO" << endl;
    return 0;
  }
  cout << "YES" << endl;
  for (int i = 1; i <= sink; ++i) {
    for (int j = max_flow.head[i]; j != 1 && j > 0; j = max_flow.pre[j]) {
      int x = i - 1;
      int y = max_flow.dest[j] - n - 1;
      if (x >= 1 && x <= n && y >= 1 && y <= n) {
        int rem = MaxFlow::INF - max_flow.limit[j];
        if (rem > 0) {
          g[x][y] += rem;
        }
      }
    }
  }
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= n; ++j) {
      cout << g[i][j] << " ";
    }
    cout << endl;
  }
  return 0;
}
