#include <bits/stdc++.h>
using namespace std;
const int INF = 1000000000;
const unsigned long long INFLL = 100000000000000000ll;
const unsigned long long MOD = 1000000007;
struct Graph {
  int n;
  vector<vector<int>> cap;
  vector<vector<int>> e;
  int s, t;
  void setSource(int n) { s = n; }
  void setSink(int n) { t = n; }
  void init(int num) {
    n = num;
    cap.resize(n + 1, vector<int>(n + 1, 0));
    e.resize(n + 1, vector<int>());
    setSource(0);
    setSink(n);
  }
  void addEdge(int a, int b, int c) {
    e[a].push_back(b);
    e[b].push_back(a);
    cap[a][b] = c;
  }
  int maxFlow() {
    int flow = 0;
    while (true) {
      queue<int> q;
      vector<bool> in(n + 1, false);
      vector<int> from(n + 1, -1);
      in[s] = true;
      q.push(s);
      while (!q.empty()) {
        int v = q.front();
        q.pop();
        if (v == t) break;
        for (int u : e[v])
          if (cap[v][u] > 0 && !in[u]) {
            in[u] = true;
            from[u] = v;
            q.push(u);
          }
      }
      if (!in[t]) break;
      int f = INF, v = t;
      while (from[v] >= 0) {
        f = min(f, cap[from[v]][v]);
        v = from[v];
      }
      flow += f;
      v = t;
      while (from[v] >= 0) {
        cap[from[v]][v] -= f;
        cap[v][from[v]] += f;
        v = from[v];
      }
    }
    return flow;
  }
};
int A[205], B[205], Roam[205][205], N, M;
unordered_set<int> E[205];
int main() {
  cin >> N >> M;
  Graph g;
  g.init(2 * N + 5);
  int s = 0, t = 2 * N + 1;
  g.setSource(s), g.setSink(t);
  for (int i = (1); i <= (N); i++) cin >> A[i];
  for (int i = (1); i <= (N); i++) cin >> B[i];
  for (int i = (1); i <= (M); i++) {
    int a, b;
    cin >> a >> b;
    E[a].insert(b), E[b].insert(a);
  }
  for (int i = (1); i <= (N); i++) g.addEdge(s, i, A[i]);
  for (int i = (1); i <= (N); i++) g.addEdge(N + i, t, B[i]);
  for (int i = (1); i <= (N); i++) E[i].insert(i);
  for (int n = (1); n <= (N); n++)
    for (int v : E[n]) g.addEdge(n, N + v, INF);
  int ff = g.maxFlow();
  for (int i = (1); i <= (N); i++)
    if (g.cap[s][i] > 0 || g.cap[N + i][t] > 0) {
      cout << "NO";
      return 0;
    }
  for (int n = (1); n <= (N); n++)
    for (int v : E[n]) Roam[n][v] += g.cap[N + v][n];
  cout << "YES\n";
  for (int i = (1); i <= (N); i++) {
    for (int j = (1); j <= (N); j++) cout << Roam[i][j] << " ";
    cout << "\n";
  }
}
