#include <bits/stdc++.h>
using namespace std;
template <typename T, typename U>
inline void amin(T &x, U y) {
  if (y < x) x = y;
}
template <typename T, typename U>
inline void amax(T &x, U y) {
  if (x < y) x = y;
}
struct MaximumFlow {
  static const int InfCapacity = 0x3f3f3f3f;
  struct Edge {
    int to;
    int capacity;
    int rev;
  };
  vector<vector<Edge> > g;
  void init(int n) { g.assign(n, vector<Edge>()); }
  void add(int i, int j, int capacity) {
    Edge e, f;
    e.to = j, f.to = i;
    e.capacity = capacity, f.capacity = 0;
    g[i].push_back(e);
    g[j].push_back(f);
    g[i].back().rev = (int)g[j].size() - 1;
    g[j].back().rev = (int)g[i].size() - 1;
  }
  void addB(int i, int j, int capacity) {
    Edge e, f;
    e.to = j, f.to = i;
    e.capacity = capacity, f.capacity = capacity;
    g[i].push_back(e);
    g[j].push_back(f);
    g[i].back().rev = (int)g[j].size() - 1;
    g[j].back().rev = (int)g[i].size() - 1;
  }
  int maximumFlow(int s, int t) {
    int n = g.size();
    vector<int> level(n);
    int total = 0;
    bool update;
    do {
      update = false;
      fill(level.begin(), level.end(), -1);
      level[s] = 0;
      queue<int> q;
      q.push(s);
      for (int d = n; !q.empty() && level[q.front()] < d;) {
        int u = q.front();
        q.pop();
        if (u == t) d = level[u];
        for (__typeof((g[u]).begin()) e = ((g[u]).begin()); e != (g[u]).end();
             ++e)
          if (e->capacity > 0 && level[e->to] == -1)
            q.push(e->to), level[e->to] = level[u] + 1;
      }
      vector<int> iter(n);
      for (int i = 0; i < n; i++) iter[i] = (int)g[i].size() - 1;
      while (1) {
        int f = augment(level, iter, s, t, InfCapacity);
        if (f == 0) break;
        total += f;
        update = true;
      }
    } while (update);
    return total;
  }
  int augment(vector<int> &level, vector<int> &iter, int u, int t, int f) {
    if (u == t || f == 0) return f;
    int lv = level[u];
    if (lv == -1) return 0;
    level[u] = -1;
    for (; iter[u] >= 0; --iter[u]) {
      Edge &e = g[u][iter[u]];
      if (level[e.to] <= lv) continue;
      int l = augment(level, iter, e.to, t, min(f, e.capacity));
      if (l == 0) continue;
      e.capacity -= l;
      g[e.to][e.rev].capacity += l;
      level[u] = lv;
      return l;
    }
    return 0;
  }
};
int main() {
  int n, m;
  while (~scanf("%d%d", &n, &m)) {
    vector<int> a(n);
    for (int(i) = 0; (i) < (int)(n); ++(i)) scanf("%d", &a[i]);
    vector<int> b(n);
    for (int(i) = 0; (i) < (int)(n); ++(i)) scanf("%d", &b[i]);
    int src = n + n, dst = src + 1;
    MaximumFlow mf;
    mf.init(dst + 1);
    for (int(i) = 0; (i) < (int)(n); ++(i)) mf.add(src, i, a[i]);
    for (int(i) = 0; (i) < (int)(n); ++(i)) mf.add(i, n + i, 0x3f3f3f3f);
    for (int(i) = 0; (i) < (int)(m); ++(i)) {
      int p, q;
      scanf("%d%d", &p, &q), --p, --q;
      mf.add(p, n + q, 0x3f3f3f3f);
      mf.add(q, n + p, 0x3f3f3f3f);
    }
    for (int(i) = 0; (i) < (int)(n); ++(i)) mf.add(n + i, dst, b[i]);
    vector<vector<MaximumFlow::Edge> > og = mf.g;
    int f = mf.maximumFlow(src, dst);
    if (f != accumulate((a).begin(), (a).end(), 0) ||
        f != accumulate((b).begin(), (b).end(), 0)) {
      puts("NO");
      continue;
    }
    vector<vector<int> > ans(n, vector<int>(n, 0));
    for (int(i) = 0; (i) < (int)(n); ++(i))
      for (int(j) = 0; (j) < (int)(mf.g[i].size()); ++(j)) {
        int e = mf.g[i][j].to;
        if (!(n <= e && e < n + n)) continue;
        int c = og[i][j].capacity - mf.g[i][j].capacity;
        ans[i][e - n] = c;
      }
    puts("YES");
    for (int(i) = 0; (i) < (int)(n); ++(i)) {
      for (int(j) = 0; (j) < (int)(n); ++(j)) {
        if (j != 0) putchar(' ');
        printf("%d", ans[i][j]);
      }
      puts("");
    }
  }
  return 0;
}
