#include <bits/stdc++.h>
using namespace std;
int a[101], b[102];
int ind[101][101];
struct FlowEdge {
  int v, u;
  long long cap, flow = 0;
  FlowEdge(int v, int u, long long cap) : v(v), u(u), cap(cap) {}
};
struct Dinic {
  const long long flow_inf = 1e18;
  vector<FlowEdge> edges;
  vector<vector<int>> adj;
  int n, m = 0;
  int s, t;
  vector<int> level, ptr;
  queue<int> q;
  Dinic(int n, int s, int t) : n(n), s(s), t(t) {
    adj.resize(n);
    level.resize(n);
    ptr.resize(n);
  }
  void add_edge(int v, 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()) {
      int v = q.front();
      q.pop();
      for (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(int v, long long pushed) {
    if (pushed == 0) return 0;
    if (v == t) return pushed;
    for (int& cid = ptr[v]; cid < (int)adj[v].size(); cid++) {
      int id = adj[v][cid];
      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;
  }
};
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= int(n); i++)
    for (int j = 1; j <= int(n); j++) ind[i][j] = -1;
  int sum1 = 0, sum2 = 0;
  for (int i = 1; i <= int(n); i++) {
    cin >> a[i];
    sum1 += a[i];
  }
  for (int i = 1; i <= int(n); i++) {
    cin >> b[i];
    sum2 += b[i];
  }
  Dinic graph(2 * n + 2, 0, 2 * n + 1);
  for (int i = 1; i <= int(n); i++) {
    ind[i][i] = graph.m;
    graph.add_edge(i, i + n, 100000);
  }
  for (int i = 1; i <= int(n); i++) graph.add_edge(0, i, a[i]);
  for (int i = 1; i <= int(n); i++) graph.add_edge(i + n, 2 * n + 1, b[i]);
  for (int i = 1; i <= int(m); i++) {
    int u, v;
    cin >> u >> v;
    ind[u][v] = graph.m;
    graph.add_edge(u, v + n, 100000);
    ind[v][u] = graph.m;
    graph.add_edge(v, u + n, 100000);
  }
  long long res = graph.flow();
  if (sum1 != sum2 || res != sum2) {
    cout << "NO" << '\n';
    return 0;
  }
  vector<vector<int>> ans(n + 1, vector<int>(n + 1, 0));
  cout << "YES" << '\n';
  for (int i = 1; i <= int(n); i++) {
    {
      for (int j = 1; j <= int(n); j++) {
        if (ind[i][j] == -1)
          cout << 0 << ' ';
        else
          cout << graph.edges[ind[i][j]].flow << ' ';
        if (j == n) cout << '\n';
      }
    }
  }
  return 0;
}
