#include <bits/stdc++.h>
using namespace std;
int n, m;
int arr[110], brr[110];
vector<vector<pair<int, int> > > adj;
int incFlow = 0;
int vis[250], parent[250], fl[250];
void updatePath(int u) {
  int par = parent[u];
  while (par != -1) {
    for (int i = 0; i < (((int)adj[par].size())); ++i) {
      if (adj[par][i].first == u) {
        adj[par][i].second -= incFlow;
      }
    }
    for (int i = 0; i < (((int)adj[u].size())); ++i) {
      if (adj[u][i].first == par) {
        adj[u][i].second += incFlow;
      }
    }
    u = par;
    par = parent[u];
  }
  return;
}
void bfs() {
  queue<int> qv;
  qv.push(0);
  fl[0] = 100000000;
  parent[0] = -1;
  vis[0] = 1;
  while (!qv.empty()) {
    int u = qv.front();
    qv.pop();
    for (int i = 0; i < (((int)adj[u].size())); ++i) {
      pair<int, int> v = adj[u][i];
      if (vis[v.first]) continue;
      if (v.second == 0) continue;
      parent[v.first] = u;
      vis[v.first] = 1;
      fl[v.first] = min(fl[u], v.second);
      if (v.first == 2 * n + 1) {
        incFlow = fl[v.first];
        updatePath(v.first);
        return;
      }
      qv.push(v.first);
    }
  }
  return;
}
int main() {
  cin >> n >> m;
  for (int i = 0; i < (n); ++i) cin >> arr[i];
  for (int i = 0; i < (n); ++i) cin >> brr[i];
  adj.resize(2 * n + 2);
  for (int i = 0; i < (m); ++i) {
    int p, q;
    cin >> p >> q;
    adj[p].push_back(make_pair(n + q, arr[p - 1]));
    adj[n + q].push_back(make_pair(p, 0));
    adj[q].push_back(make_pair(n + p, arr[q - 1]));
    adj[n + p].push_back(make_pair(q, 0));
  }
  for (int i = 1; i < (n + 1); ++i) {
    adj[0].push_back(make_pair(i, arr[i - 1]));
    adj[i].push_back(make_pair(0, 0));
    adj[i].push_back(make_pair(n + i, arr[i - 1]));
    adj[n + i].push_back(make_pair(i, 0));
    adj[n + i].push_back(make_pair(2 * n + 1, brr[i - 1]));
    adj[2 * n + 1].push_back(make_pair(n + i, 0));
  }
  int flow = 0;
  while (1) {
    incFlow = 0;
    memset(vis, 0, sizeof vis);
    memset(parent, -1, sizeof parent);
    memset(fl, 0, sizeof fl);
    bfs();
    if (incFlow == 0)
      break;
    else
      flow += incFlow;
  }
  int sum = 0;
  for (int i = 0; i < (n); ++i) {
    sum += brr[i] - arr[i];
  }
  for (int i = 0; i < (n); ++i) {
    flow -= arr[i];
  }
  int went[250];
  if (flow == 0 && sum == 0) {
    cout << "YES" << endl;
    for (int i = 1; i < n + 1; i++) {
      memset(went, 0, sizeof went);
      for (int j = 0; j < (adj[i].size()); ++j) {
        pair<int, int> vv = adj[i][j];
        int x = 0;
        x = arr[i - 1] - vv.second;
        if (vv.first == 0) continue;
        went[vv.first - n - 1] = x;
      }
      for (int j = 0; j < (n); ++j) {
        cout << went[j] << " ";
      }
      cout << endl;
    }
  } else
    cout << "NO" << endl;
  return 0;
}
