#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:667772160")
using namespace std;
struct __isoff {
  __isoff() {
    if (0) freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout);
    srand(time(0));
  }
  ~__isoff() {}
} __osafwf;
const unsigned long long p1 = 31;
const unsigned long long p2 = 29;
const double eps = 1e-8;
const double pi = acos(-1.0);
const long long inf = 1e18 + 7;
const int infi = 1e9 + 7;
const long long dd = 1e5;
const long long mod = 1e9 + 7;
struct eg {
  int to, mF, F, q;
  eg(int _t, int _mf, int f, int Q) : to(_t), mF(_mf), F(f), q(Q) {}
};
vector<vector<eg> > P;
void addeg(int a, int b, int ls) {
  P[a].push_back(eg(b, ls, 0, P[b].size()));
  P[b].push_back(eg(a, 0, 0, P[a].size() - 1));
}
int T[dd], ti = 1, t = 1;
bool dfs(int v, int q) {
  if (T[v] == ti) return 0;
  if (v == t) return 1;
  T[v] = ti;
  for (int i = 0; i < P[v].size(); i++) {
    if (P[v][i].F != P[v][i].mF && P[v][i].F + q <= P[v][i].mF)
      if (dfs(P[v][i].to, q)) {
        P[P[v][i].to][P[v][i].q].F -= q;
        P[v][i].F += q;
        return 1;
      }
  }
  return 0;
}
bool gg;
void magec(int v, int s) {
  ti++;
  while (dfs(v, 1 << s)) ti++;
}
int n, m;
vector<int> A, B;
int res[105][105];
int main() {
  cin >> n >> m;
  int a1, a2;
  a1 = a2 = 0;
  A.resize(n);
  B.resize(n);
  P.resize(100 * n + 200);
  for (long long i = 0; i < (long long)n; i++) {
    cin >> A[i];
    a1 += A[i];
  }
  for (long long i = 0; i < (long long)n; i++) {
    cin >> B[i];
    a2 += B[i];
  }
  if (a1 != a2) {
    cout << "NO";
    return 0;
  }
  for (long long i = 0; i < (long long)m; i++) {
    int a, b;
    cin >> a >> b;
    a++, b++;
    addeg(a, n + b, 101);
    addeg(b, n + a, 101);
  }
  for (long long i = 0; i < (long long)n; i++) {
    addeg(i + 2, i + 2 + n, 101);
  }
  for (long long i = 0; i < (long long)n; i++) {
    addeg(0, i + 2, A[i]);
    addeg(i + 2 + n, 1, B[i]);
  }
  for (int i = 16; i >= 0; i--) magec(0, i);
  int t = 0;
  for (long long i = 0; i < (long long)P[1].size(); i++) {
    t -= P[1][i].F;
  }
  if (t != a1) {
    cout << "NO";
    return 0;
  }
  for (long long i = 0; i < (long long)n; i++) {
    int v = i + 2;
    for (long long j = 0; j < (long long)P[v].size(); j++) {
      if (P[v][j].mF > 0) {
        int u = P[v][j].to - n;
        res[v - 2][u - 2] += P[v][j].F;
      }
    }
  }
  cout << "YES\n";
  for (long long i = 0; i < (long long)n; i++) {
    for (long long j = 0; j < (long long)n; j++) cout << res[i][j] << ' ';
    cout << '\n';
  }
}
