#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC optimization("unroll-loops, no-stack-protector")
#pragma GCC target("avx,avx2,fma")
class min_cost_flow {
 public:
  struct edge_node {
    int to;
    int capacity, flow;
    int cost;
    int reverse_id;
  };
  int VERYBIG = 2E9;
  bool min_cost_needed;
  int n, f, mf, totalcost;
  int s, t;
  vector<vector<edge_node>> adj;
  vector<int> pp, ppid;
  min_cost_flow(int nn, int start, int terminal) {
    n = nn;
    s = start;
    t = terminal;
    adj.clear();
    adj.resize(nn);
  }
  void add_path(int a, int b, int forward_capacity, int backward_capacity = 0,
                int forward_cost = 0, int backward_cost = 0) {
    int ida = adj[a].size(), idb = adj[b].size();
    adj[a].push_back({b, forward_capacity, 0, forward_cost, idb});
    adj[b].push_back({a, backward_capacity, 0, backward_cost, ida});
  }
  void clear_flow() {
    int i;
    for (i = 0; i < n; i++) {
      for (auto p : adj[i]) p.flow = 0;
    }
  }
  void augment(int v, int maxflow) {
    if (v == s) {
      f = maxflow;
    } else if (pp[v] != -1) {
      int parent = pp[v], pid = ppid[v], rid = adj[parent][pid].reverse_id;
      int available_flow = adj[parent][pid].capacity - adj[parent][pid].flow;
      if (maxflow < available_flow)
        augment(parent, maxflow);
      else
        augment(parent, available_flow);
      adj[parent][pid].flow += f;
      adj[v][rid].flow -= f;
      totalcost += f * (adj[parent][pid].cost - adj[v][rid].cost);
    }
  }
  void solve_flow() {
    mf = 0;
    totalcost = 0;
    while (1) {
      int i, j, k;
      vector<int> dist, mincost;
      dist.assign(n, VERYBIG);
      dist[s] = 0;
      queue<int> q;
      q.push(s);
      pp.assign(n, -1);
      ppid.assign(n, -1);
      while (!q.empty()) {
        int u = q.front(), v;
        q.pop();
        for (i = 0; i < adj[u].size(); i++) {
          v = adj[u][i].to;
          if ((adj[u][i].flow < adj[u][i].capacity) &&
              (dist[v] > dist[u] + adj[u][i].cost)) {
            dist[v] = dist[u] + adj[u][i].cost;
            q.push(v);
            pp[v] = u;
            ppid[v] = i;
          }
        }
      }
      f = 0;
      augment(t, VERYBIG);
      if (f == 0) break;
      if (f == VERYBIG) break;
      mf += f;
    }
  }
};
int dist[620][620];
int start[620];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m, i, j, k, sa, sb, aa, bb;
  cin >> n >> m;
  vector<int> a(n), b(n);
  sa = 0;
  for (i = 0; i < n; i++) {
    cin >> a[i];
    sa += a[i];
  }
  sb = 0;
  for (i = 0; i < n; i++) {
    cin >> b[i];
    sb += b[i];
  }
  min_cost_flow fl(n + n + 2, 0, n + n + 1);
  for (i = 0; i < n; i++) {
    fl.add_path(0, i + 1, a[i]);
    fl.add_path(i + n + 1, n + n + 1, b[i]);
    fl.add_path(i + 1, i + n + 1, sb);
  }
  while (m--) {
    cin >> aa >> bb;
    fl.add_path(aa, bb + n, sb);
    fl.add_path(bb, aa + n, sb);
  }
  fl.solve_flow();
  if ((sa != sb) || (fl.mf != sb))
    cout << "NO\n";
  else {
    cout << "YES\n";
    vector<vector<int>> ans(n, vector<int>(n, 0));
    for (i = 1; i <= n; i++) {
      for (auto p : fl.adj[i]) {
        if ((p.to >= n + 1) && (p.to <= n + n) && (p.flow != 0))
          ans[i - 1][p.to - n - 1] = abs(p.flow);
      }
    }
    for (i = 0; i < n; i++) {
      for (j = 0; j < n; j++) cout << ans[i][j] << " ";
      cout << "\n";
    }
  }
  return 0;
}
