#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9;
const int64_t INFLL = 1e18;
const double EPS = 1e-9;
template <class T>
T &chmin(T &a, const T &b) {
  return a = min(a, b);
}
template <class T>
T &chmax(T &a, const T &b) {
  return a = max(a, b);
}
const int MAX_V = 310;
struct edge {
  int to, cap, rev;
};
struct Maxflow {
  vector<edge> G[MAX_V];
  bool used[MAX_V];
  pair<int, int> add_edge(int from, int to, int cap) {
    G[from].push_back((edge){to, cap, int(G[to].size())});
    G[to].push_back((edge){from, 0, int(G[from].size() - 1)});
    return pair<int, int>(to, G[to].size() - 1);
  }
  int dfs(int v, int t, int f) {
    if (v == t) return f;
    used[v] = true;
    for (int i = 0; i < G[v].size(); i++) {
      edge &e = G[v][i];
      if (!used[e.to] && e.cap > 0) {
        int d = dfs(e.to, t, min(f, e.cap));
        if (d > 0) {
          e.cap -= d;
          G[e.to][e.rev].cap += d;
          return d;
        }
      }
    }
    return 0;
  }
  int max_flow(int s, int t) {
    int flow = 0;
    while (1) {
      memset(used, 0, sizeof(used));
      int f = dfs(s, t, INF);
      if (f == 0) return flow;
      flow += f;
    }
  }
};
const int MAX_N = 310;
const pair<int, int> INI = pair<int, int>(-1, -1);
Maxflow mf;
int a[MAX_N];
int b[MAX_N];
bool f[MAX_N][MAX_N];
pair<int, int> G[MAX_N][MAX_N];
int main() {
  int n, m;
  cin >> n >> m;
  int s = 2 * n;
  int t = s + 1;
  for (int i = (0); i < (int)(n); ++i) cin >> a[i];
  for (int i = (0); i < (int)(n); ++i) cin >> b[i];
  int sum = 0;
  for (int i = (0); i < (int)(n); ++i) sum += b[i];
  int suma = 0;
  for (int i = (0); i < (int)(n); ++i) suma += a[i];
  for (int i = (0); i < (int)(n); ++i)
    for (int j = (0); j < (int)(n); ++j) G[i][j] = INI;
  for (int i = (0); i < (int)(m); ++i) {
    int c, d;
    cin >> c >> d;
    c--;
    d--;
    if (f[c][d]) continue;
    f[c][d] = f[d][c] = true;
    G[c][d] = mf.add_edge(c, n + d, INF);
    G[d][c] = mf.add_edge(d, n + c, INF);
  }
  for (int i = (0); i < (int)(n); ++i) G[i][i] = mf.add_edge(i, n + i, INF);
  for (int i = (0); i < (int)(n); ++i) mf.add_edge(s, i, a[i]);
  for (int i = (0); i < (int)(n); ++i) mf.add_edge(n + i, t, b[i]);
  if (mf.max_flow(s, t) == sum && sum == suma) {
    cout << "YES" << endl;
    for (int i = (0); i < (int)(n); ++i) {
      for (int j = (0); j < (int)(n); ++j) {
        if (j != 0) cout << " ";
        if (G[i][j] != INI)
          cout << mf.G[G[i][j].first][G[i][j].second].cap;
        else
          cout << 0;
      }
      cout << endl;
    }
  } else {
    cout << "NO" << endl;
  }
  return 0;
}
