#include <bits/stdc++.h>
using namespace std;
struct FlowEdge {
  long long int v, u;
  long long cap, flow = 0;
  FlowEdge(long long int v, long long int u, long long cap)
      : v(v), u(u), cap(cap) {}
};
struct Dinic {
  const long long flow_inf = 1e18;
  vector<FlowEdge> edges;
  vector<vector<long long int>> adj;
  long long int n, m = 0;
  long long int s, t;
  vector<long long int> level, ptr;
  queue<long long int> q;
  Dinic(long long int n, long long int s, long long int t) : n(n), s(s), t(t) {
    adj.resize(n);
    level.resize(n);
    ptr.resize(n);
  }
  void add_edge(long long int v, long long int u, long long cap) {
    edges.emplace_back(v, u, cap);
    edges.emplace_back(u, v, 0);
    adj[v].push_back(m);
    adj[u].push_back(m + 1);
    m += 2;
  }
  bool bfs() {
    while (!q.empty()) {
      long long int v = q.front();
      q.pop();
      for (long long int id : adj[v]) {
        if (edges[id].cap - edges[id].flow < 1) continue;
        if (level[edges[id].u] != -1) continue;
        level[edges[id].u] = level[v] + 1;
        q.push(edges[id].u);
      }
    }
    return level[t] != -1;
  }
  long long dfs(long long int v, long long pushed) {
    if (pushed == 0) return 0;
    if (v == t) return pushed;
    for (long long int& cid = ptr[v]; cid < (long long int)adj[v].size();
         cid++) {
      long long int id = adj[v][cid];
      long long int u = edges[id].u;
      if (level[v] + 1 != level[u] || edges[id].cap - edges[id].flow < 1)
        continue;
      long long tr = dfs(u, min(pushed, edges[id].cap - edges[id].flow));
      if (tr == 0) continue;
      edges[id].flow += tr;
      edges[id ^ 1].flow -= tr;
      return tr;
    }
    return 0;
  }
  long long flow() {
    long long f = 0;
    while (true) {
      fill(level.begin(), level.end(), -1);
      level[s] = 0;
      q.push(s);
      if (!bfs()) break;
      fill(ptr.begin(), ptr.end(), 0);
      while (long long pushed = dfs(s, flow_inf)) {
        f += pushed;
      }
    }
    return f;
  }
};
long long int a[105], b[105], res[105][105], hell = pow(10, 15);
void solve() {
  long long int n, m, sum = 0, sum0 = 0;
  cin >> n >> m;
  Dinic d = Dinic(2 * n + 2, 0, 2 * n + 1);
  for (long long int i = 1; i <= n; i++) {
    cin >> a[i];
    sum0 += a[i];
  }
  for (long long int i = 1; i <= n; i++) {
    cin >> b[i];
    sum += b[i];
  }
  for (long long int i = 0; i < m; i++) {
    long long int u, v;
    cin >> u >> v;
    d.add_edge(u, v + n, hell);
    d.add_edge(v, u + n, hell);
  }
  for (long long int i = 1; i <= n; i++) {
    d.add_edge(0, i, a[i]);
    d.add_edge(i + n, 2 * n + 1, b[i]);
    d.add_edge(i, i + n, hell);
  }
  if (sum != d.flow() || sum != sum0) {
    cout << "NO";
    exit(0);
  }
  cout << "YES\n";
  vector<FlowEdge> edg = d.edges;
  for (long long int i = 0; i < edg.size(); i++) {
    long long int u = edg[i].u, v = edg[i].v;
    if (1 <= u && u <= n && v > n && v <= 2 * n) res[u][v - n] = (-edg[i].flow);
  }
  for (long long int i = 1; i <= n; i++) {
    for (long long int j = 1; j <= n; j++) cout << res[i][j] << " ";
    cout << endl;
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int q = 1;
  for (long long int i = 1; i <= q; i++) solve();
}
