#include <bits/stdc++.h>
using namespace std;
vector<long long> graph[310];
long long fl[310][310], cp[310][310];
long long dis[310];
deque<long long> que;
void add_edge(long long u, long long v, long long w, long long fff) {
  graph[u].push_back(v);
  graph[v].push_back(u);
  cp[u][v] += w;
}
bool bfs(long long src, long long sink) {
  memset((dis), (-1), sizeof(dis));
  dis[src] = 0;
  queue<long long> q;
  q.push(src);
  while (!q.empty()) {
    long long u = q.front();
    q.pop();
    for (long long i = 0; i < graph[u].size(); i++) {
      long long v = graph[u][i];
      if (dis[v] == -1 && (fl[u][v] < cp[u][v])) {
        q.push(v);
        dis[v] = dis[u] + 1;
      }
    }
  }
  return dis[sink] != -1;
}
long long ind[310];
long long dfs(long long src, long long flow, long long sink) {
  if (!flow) return 0;
  if (src == sink) return flow;
  for (; ind[src] < graph[src].size(); ++ind[src]) {
    long long v = graph[src][ind[src]];
    if (dis[v] != dis[src] + 1) continue;
    long long curr_flow = dfs(v, min(flow, cp[src][v] - fl[src][v]), sink);
    if (curr_flow) {
      fl[src][v] += curr_flow;
      fl[v][src] -= curr_flow;
      return curr_flow;
    }
  }
  return 0;
}
long long dinic(long long src, long long sink) {
  long long flow = 0;
  long long INF = 11111111111111;
  while (1) {
    if (!bfs(src, sink)) break;
    memset((ind), (0), sizeof(ind));
    while (long long curr_flow = dfs(src, INF, sink)) flow += curr_flow;
  }
  return flow;
}
vector<long long> graph2[310];
long long n, m;
long long a[110];
long long b[110];
int main() {
  scanf("%lld", &n);
  scanf("%lld", &m);
  long long sum1 = 0;
  long long sum2 = 0;
  for (long long i = 1; i <= n; i++) {
    scanf("%lld", &a[i]);
    sum1 += a[i];
  }
  for (long long i = 1; i <= n; i++) {
    scanf("%lld", &b[i]);
    sum2 += b[i];
  }
  for (long long i = 1; i <= m; i++) {
    long long u, v;
    scanf("%lld", &u);
    scanf("%lld", &v);
    graph2[u].push_back(v);
    graph2[v].push_back(u);
  }
  if (sum1 != sum2) {
    cout << "NO" << endl;
    return 0;
  }
  long long src = 0;
  long long sink = n + n + 1;
  for (long long i = 1; i <= n; i++) {
    add_edge(src, i, a[i], 0);
  }
  for (long long i = 1; i <= n; i++) {
    add_edge(i, n + i, 1e15, 0);
    for (long long j = 0; j < graph2[i].size(); j++) {
      long long adj = graph2[i][j];
      add_edge(i, n + adj, 1e15, 0);
    }
  }
  for (long long i = n + 1; i <= n + n; i++) {
    add_edge(i, sink, b[i - n], 0);
  }
  dinic(src, sink);
  bool f = 0;
  for (long long i = n + 1; i <= n + n; i++) {
    if (fl[i][sink] < b[i - n]) {
      f = 1;
      break;
    }
  }
  if (f) {
    cout << "NO" << endl;
    return 0;
  }
  cout << "YES" << endl;
  for (long long i = 1; i <= n; i++) {
    for (long long j = n + 1; j <= n + n; j++) {
      cout << fl[i][j] << " ";
    }
    cout << endl;
  }
  return 0;
}
