#include <bits/stdc++.h>
using namespace std;
using ld = long double;
using vd = vector<ld>;
using vvd = vector<vd>;
using vi = vector<int>;
using vvii = vector<vector<pair<int, int>>>;
const ld EPS = 1e-9;
inline bool lessPair(ld d1, int i1, ld d2, int i2) {
  return abs(d1 - d2) > EPS ? d1 < d2 : i1 < i2;
}
struct LPSolver {
  int m, n;
  vi B, N;
  vvd D;
  LPSolver(const vvd &A, const vd &b, const vd &c)
      : m(((int)b.size())),
        n(((int)c.size())),
        B(m + 1),
        N(n + 1),
        D(m + 1, vd(n + 1, 0)) {
    for (int i = 0; i < (m); i++) {
      for (int j = 0; j < (n); j++) D[i + 1][j] = A[i][j];
      D[i + 1][n] = b[i];
    }
    for (int i = 0; i < (n); i++) D[0][i] = -c[i];
    for (int i = 0; i < (m + 1); i++) B[i] = -i;
    for (int j = 0; j < (n + 1); j++) N[j] = j;
  }
  void Pivot(int r, int s) {
    for (int i = 0; i < (m + 1); i++)
      if (i != r && ((D[i][s] > EPS) || (D[i][s] < -EPS)))
        for (int j = 0; j < (n + 1); j++)
          if (j != s) D[i][j] -= D[r][j] * D[i][s] / D[r][s];
    for (int j = 0; j < (n + 1); j++)
      if (j != s) D[r][j] /= D[r][s];
    for (int i = 0; i < (m + 1); i++)
      if (i != r) D[i][s] /= -D[r][s];
    D[r][s] = 1.0 / D[r][s];
    swap(B[r], N[s]);
  }
  ld Solve(vector<ld> &x) {
    while (true) {
      int ii = 1, jj = 0;
      for (int i = 1; i <= (m); i++)
        if (lessPair(D[i][n], B[i], D[ii][n], B[ii])) ii = i;
      if (D[ii][n] > -EPS) break;
      for (int j = 0; j < (n); j++)
        if (D[ii][j] < D[ii][jj]) jj = j;
      if (D[ii][jj] > -EPS) return -numeric_limits<ld>::infinity();
      Pivot(ii, jj);
    }
    while (true) {
      int ii = 1, jj = 0;
      for (int j = 0; j < (n); j++)
        if (lessPair(D[0][j], N[j], D[0][jj], N[jj])) jj = j;
      if (D[0][jj] > -EPS) break;
      for (int i = 1; i <= (m); i++)
        if (D[i][jj] > EPS &&
            (D[ii][jj] < EPS ||
             lessPair(D[i][n] / D[i][jj], B[i], D[ii][n] / D[ii][jj], B[ii])))
          ii = i;
      if (D[ii][jj] < EPS) return numeric_limits<ld>::infinity();
      Pivot(ii, jj);
    }
    x.assign(n, 0);
    for (int i = 1; i <= (m); i++)
      if (B[i] >= 0) x[B[i]] = D[i][n];
    return D[0][n];
  }
};
int main() {
  cin.tie(0)->sync_with_stdio(0);
  int n, m, u, v, sz;
  cin >> n >> m;
  vi a(n), b(n), c(n);
  for (int i = 0; i < (n); i++) cin >> a[i];
  for (int i = 0; i < (n); i++) cin >> b[i];
  vector<vi> mat(n, vi(n, 0));
  for (int i = 0; i < (m); i++) {
    cin >> u >> v;
    u--;
    v--;
    mat[u][v] = mat[v][u] = 1;
  }
  for (int i = 0; i < (n); i++) c[i] = b[i] - a[i];
  if (accumulate(c.begin(), c.end(), 0) != 0) return (cout << "NO\n", 0);
  vvd A;
  vd B, C(n * n);
  for (int i = 0; i < (n); i++) {
    vd l(n * n);
    l[i * n + i] = 1;
    A.push_back(l);
    B.push_back(a[i]);
  }
  for (int i = 0; i < (n); i++) {
    vd l(n * n);
    for (int j = 0; j < (n); j++)
      if (mat[i][j]) l[i * n + j] = 1;
    A.push_back(l);
    B.push_back(a[i]);
  }
  for (int i = 0; i < (n); i++) {
    vd l1(n * n), l2(n * n);
    for (int j = 0; j < (n); j++)
      if (mat[i][j]) {
        l1[i * n + j] = -1;
        l2[i * n + j] = 1;
        l1[j * n + i] = 1;
        l2[j * n + i] = -1;
      }
    l1[i * n + i] = 1;
    l2[i * n + i] = -1;
    A.push_back(l1);
    A.push_back(l2);
    B.push_back(b[i]);
    B.push_back(-b[i]);
  }
  LPSolver LPS(A, B, C);
  vd X;
  int ans = round(-LPS.Solve(X));
  if (((int)X.size()) < n) {
    cout << "NO\n";
    return 0;
  }
  cout << "YES\n";
  for (int i = 0; i < (n); i++)
    for (int j = 0; j < (n); j++)
      if (i != j) X[i * n + i] -= X[i * n + j];
  for (int i = 0; i < (n); i++)
    for (int j = 0; j < (n); j++) cout << X[i * n + j] << "\n "[j < n - 1];
  return 0;
}
