#include <bits/stdc++.h>
using namespace std;
int n, m, x, y, graph[202][202], parent[202];
bool done[202];
bool flowBfs(int source, int sink) {
  queue<int> q;
  q.push(source);
  done[source] = true;
  parent[source] = -1;
  while (!q.empty()) {
    int from = q.front();
    q.pop();
    for (int i = 0; i < 202; i++) {
      if (!done[i] && graph[from][i] != 0) {
        q.push(i);
        parent[i] = from;
        done[i] = true;
      }
    }
  }
  return done[sink];
}
int edmondsKarp(int source, int sink) {
  int maxFlow = 0;
  while (1) {
    memset(done, 0, sizeof(done));
    if (!flowBfs(source, sink)) break;
    int bestFlow = 100000000;
    for (int idx = sink; idx != source; idx = parent[idx]) {
      bestFlow = min(bestFlow, graph[parent[idx]][idx]);
    }
    for (int idx = sink; idx != source; idx = parent[idx]) {
      graph[idx][parent[idx]] += bestFlow;
      graph[parent[idx]][idx] -= bestFlow;
    }
    maxFlow += bestFlow;
  }
  return maxFlow;
}
int main() {
  scanf("%d %d", &n, &m);
  memset(graph, 0, sizeof(graph));
  int current = 0, need = 0;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &x);
    graph[0][i] = x;
    current += x;
  }
  for (int i = 1; i <= n; i++) {
    scanf("%d", &y);
    graph[i + 100][201] = y;
    graph[i][i + 100] = 100000000;
    need += y;
  }
  for (int i = 0; i < m; i++) {
    scanf("%d %d", &x, &y);
    graph[x][y + 100] = 100000000;
    graph[y][x + 100] = 100000000;
  }
  int res = edmondsKarp(0, 201);
  if (res == need && current == need) {
    puts("YES");
    for (int i = 1; i <= n; i++) {
      for (int j = 1; j <= n; j++) {
        if (graph[i][j + 100] == 0)
          printf("%d ", 0);
        else
          printf("%d ", 100000000 - graph[i][j + 100]);
      }
      puts("");
    }
  } else
    puts("NO");
  return 0;
}
