#include <bits/stdc++.h>
const long long inf = 1e9;
using namespace std;
struct Edge {
  int u, v;
  long long cap, flow;
  Edge() {}
  Edge(int u, int v, long long cap) : u(u), v(v), cap(cap), flow(0) {}
};
struct Dinic {
  int N;
  vector<Edge> E;
  vector<vector<int> > g;
  vector<int> d, pt;
  Dinic(int N) : N(N), E(0), g(N), d(N), pt(N) {}
  void addEdge(int u, int v, long long cap) {
    if (u != v) {
      E.emplace_back(u, v, cap);
      g[u].emplace_back(E.size() - 1);
      E.emplace_back(v, u, 0);
      g[v].emplace_back(E.size() - 1);
    }
  }
  bool BFS(int S, int T) {
    queue<int> q({S});
    fill(d.begin(), d.end(), N + 1);
    d[S] = 0;
    while (!q.empty()) {
      int u = q.front();
      q.pop();
      if (u == T) break;
      for (int k : g[u]) {
        Edge &e = E[k];
        if (e.flow < e.cap && d[e.v] > d[e.u] + 1) {
          d[e.v] = d[e.u] + 1;
          q.emplace(e.v);
        }
      }
    }
    return d[T] != N + 1;
  }
  long long DFS(int u, int T, long long flow = -1) {
    if (u == T || flow == 0) return flow;
    for (int &i = pt[u]; i < g[u].size(); ++i) {
      Edge &e = E[g[u][i]];
      Edge &oe = E[g[u][i] ^ 1];
      if (d[e.v] == d[e.u] + 1) {
        long long amt = e.cap - e.flow;
        if (flow != -1 && amt > flow) amt = flow;
        if (long long pushed = DFS(e.v, T, amt)) {
          e.flow += pushed;
          oe.flow -= pushed;
          return pushed;
        }
      }
    }
    return 0;
  }
  long long MaxFlow(int S, int T) {
    long long total = 0;
    while (BFS(S, T)) {
      fill(pt.begin(), pt.end(), 0);
      while (long long flow = DFS(S, T)) total += flow;
    }
    return total;
  }
  vector<Edge> retrieveFlow() {
    vector<Edge> v;
    for (auto &e : E) {
      if (e.cap != 0 && e.flow != 0) v.push_back(e);
    }
    return v;
  }
};
int ans[105][105];
int main() {
  ios_base::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  Dinic maxflow(2 * n + 2);
  int source = 2 * n;
  int sink = 2 * n + 1;
  long long sumA = 0;
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    sumA += a;
    maxflow.addEdge(source, i, a);
  }
  long long sumB = 0;
  for (int i = 0; i < n; i++) {
    int b;
    cin >> b;
    sumB += b;
    maxflow.addEdge(i + n, sink, b);
  }
  if (sumA != sumB) {
    cout << "NO";
    exit(0);
  }
  for (int i = 0; i < n; i++) maxflow.addEdge(i, i + n, inf);
  for (int i = 0; i < m; i++) {
    int u, v;
    cin >> u >> v;
    u--;
    v--;
    maxflow.addEdge(u, v + n, inf);
    maxflow.addEdge(v, u + n, inf);
  }
  if (maxflow.MaxFlow(source, sink) != sumA) {
    cout << "NO";
    exit(0);
  }
  for (auto e : maxflow.retrieveFlow()) {
    if (e.u == source || e.v == sink) continue;
    ans[e.u][e.v - n] = e.flow;
  }
  cout << "YES\n";
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) cout << ans[i][j] << " ";
    cout << "\n";
  }
}
