#include <bits/stdc++.h>
using namespace std;
struct Edge {
  int from, to, cap, flow, index;
  Edge(int from, int to, int cap, int flow, int index)
      : from(from), to(to), cap(cap), flow(flow), index(index) {}
  long long rcap() { return cap - flow; }
};
struct Dinic {
  int N;
  vector<vector<Edge> > G;
  vector<vector<Edge *> > Lf;
  vector<int> layer;
  vector<int> Q;
  Dinic(int N) : N(N), G(N), Q(N) {}
  void AddEdge(int from, int to, int cap) {
    if (from == to) return;
    G[from].push_back(Edge(from, to, cap, 0, G[to].size()));
    G[to].push_back(Edge(to, from, 0, 0, G[from].size() - 1));
  }
  long long BlockingFlow(int s, int t) {
    layer.clear();
    layer.resize(N, -1);
    layer[s] = 0;
    Lf.clear();
    Lf.resize(N);
    int head = 0, tail = 0;
    Q[tail++] = s;
    while (head < tail) {
      int x = Q[head++];
      for (int i = 0; i < G[x].size(); i++) {
        Edge &e = G[x][i];
        if (e.rcap() <= 0) continue;
        if (layer[e.to] == -1) {
          layer[e.to] = layer[e.from] + 1;
          Q[tail++] = e.to;
        }
        if (layer[e.to] > layer[e.from]) {
          Lf[e.from].push_back(&e);
        }
      }
    }
    if (layer[t] == -1) return 0;
    long long totflow = 0;
    vector<Edge *> P;
    while (!Lf[s].empty()) {
      int curr = P.empty() ? s : P.back()->to;
      if (curr == t) {
        long long amt = P.front()->rcap();
        for (int i = 0; i < P.size(); ++i) {
          amt = min(amt, P[i]->rcap());
        }
        totflow += amt;
        for (int i = P.size() - 1; i >= 0; --i) {
          P[i]->flow += amt;
          G[P[i]->to][P[i]->index].flow -= amt;
          if (P[i]->rcap() <= 0) {
            Lf[P[i]->from].pop_back();
            P.resize(i);
          }
        }
      } else if (Lf[curr].empty()) {
        P.pop_back();
        for (int i = 0; i < N; ++i)
          for (int j = 0; j < Lf[i].size(); ++j)
            if (Lf[i][j]->to == curr) Lf[i].erase(Lf[i].begin() + j);
      } else {
        P.push_back(Lf[curr].back());
      }
    }
    return totflow;
  }
  long long GetMaxFlow(int s, int t) {
    long long totflow = 0;
    while (long long flow = BlockingFlow(s, t)) totflow += flow;
    return totflow;
  }
};
int n, m, a[103], b[105];
int anss[105][105];
int main() {
  ios::sync_with_stdio(0);
  cin >> n >> m;
  int sum = 0, sum2 = 0;
  for (int i = 1; i <= n; i++) cin >> a[i], sum2 += a[i];
  for (int i = 1; i <= n; i++) cin >> b[i], sum += b[i];
  int source = 0;
  if (sum != sum2) {
    cout << "NO" << endl;
    return 0;
  }
  int sink = 250;
  Dinic g(255);
  for (int i = 1; i <= n; i++) {
    g.AddEdge(source, i, a[i]);
    g.AddEdge(i, i + 102, a[i]);
    g.AddEdge(i + 102, sink, b[i]);
  }
  for (int i = 0; i < m; i++) {
    int x, y;
    cin >> x >> y;
    g.AddEdge(x, y + 102, a[x]);
    g.AddEdge(y, x + 102, a[y]);
  }
  int ans = g.GetMaxFlow(source, sink);
  if (ans != sum) {
    cout << "NO" << endl;
    return 0;
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j < g.G[i].size(); j++) {
      int u = g.G[i][j].to;
      int x = g.G[i][j].flow;
      if (u >= 103 && u <= 203) anss[i][u - 102] = x;
    }
  }
  cout << "YES" << endl;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      cout << anss[i][j] << " ";
    }
    cout << endl;
  }
  return 0;
}
