#include <bits/stdc++.h>
using namespace std;
int N, M;
int F[205][205];
int INF = 100000;
int num1, num2;
int P[205], Q[205];
int ans[105][105];
int A[105];
bool flag[205];
int dfs(int s, int f) {
  if (s == 2 * N + 1) {
    return f;
  }
  flag[s] = true;
  for (int i = 0; i < 2 * N + 2; i++) {
    if (F[s][i] > 0 && !flag[i]) {
      int ff = dfs(i, min(f, F[s][i]));
      if (ff > 0) {
        F[s][i] -= ff;
        F[i][s] += ff;
        return ff;
      }
    }
  }
  return 0;
}
int main() {
  scanf("%d%d", &N, &M);
  for (int i = 0; i < N; i++) {
    scanf("%d", &A[i]);
    num1 += A[i];
    F[0][i + 1] = A[i];
  }
  for (int i = 0; i < N; i++) {
    int B;
    scanf("%d", &B);
    num2 += B;
    F[N + 1 + i][2 * N + 1] = B;
  }
  if (num1 != num2) {
    printf("NO\n");
    return 0;
  }
  for (int i = 0; i < M; i++) {
    scanf("%d%d", &P[i], &Q[i]);
    F[P[i]][Q[i] + N] = INF;
    F[Q[i]][P[i] + N] = INF;
  }
  for (int i = 0; i < N; i++) {
    F[i + 1][N + i + 1] = INF;
  }
  int flow = 0;
  while (true) {
    for (int i = 0; i < 2 * N + 2; i++) flag[i] = false;
    int f = dfs(0, INF);
    if (f == 0) break;
    flow += f;
  }
  if (flow != num1) {
    printf("NO\n");
    return 0;
  }
  printf("YES\n");
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      if (j != N - 1)
        printf("%d ", F[j + N + 1][i + 1]);
      else
        printf("%d\n", F[j + N + 1][i + 1]);
    }
  }
  return 0;
}
