#include <bits/stdc++.h>   using namespace std;   struct Dicnic {     struct Edge {       int from, to, cap, flow, next;       Edge() {}       Edge(int from, int to, int cap, int flow, int next) {         this->from = from;         this->to = to;         this->cap = cap;         this->flow = flow;         this->next = next;       }     } ed[100005];     int n, m, s, t, lnum, head, tail;     int cur[100005], start[100005], que[100005 * 10], dis[100005];     void init() {       lnum = 0;       for (int i = s; i <= t; i++) start[i] = -1;     }     void add(int x, int y, int c) {       ed[lnum] = Edge(x, y, c, 0, start[x]);       start[x] = lnum++;       ed[lnum] = Edge(y, x, 0, 0, start[y]);       start[y] = lnum++;     }     bool bfs() {       for (int i = s; i <= t; i++) dis[i] = -1;       head = tail = 0;       dis[s] = 0;       que[tail++] = s;       while (head < tail) {         int x = que[head++];         for (int i = start[x]; ~i; i = ed[i].next) {           Edge& e = ed[i];           if (e.cap > e.flow && dis[e.to] == -1) {             dis[e.to] = dis[x] + 1;             que[tail++] = e.to;           }         }       }       return dis[t] != -1;     }     int dfs(int x, int a) {       if (x == t || a == 0) return a;       int flow = 0, f;       for (int& i = cur[x]; ~i; i = ed[i].next) {         Edge& e = ed[i];         if (dis[e.to] == dis[x] + 1 &&             (f = dfs(e.to, min(a, e.cap - e.flow))) > 0) {           e.flow += f;           ed[i ^ 1].flow -= f;           flow += f;           a -= f;           if (!a) break;         }       }       return flow;     }     int Maxflow() {       int flow = 0;       while (bfs()) {         for (int i = s; i <= t; i++) cur[i] = start[i];         flow += dfs(s, 99999999);       }       return flow;     }   } dic;   struct edge {     int to, next;     edge() {}     edge(int to, int next) {       this->to = to;       this->next = next;     }   } ed[405];   int head[105], lnum;   void addline(int from, int to) {     ed[lnum] = edge(to, head[from]);     head[from] = lnum++;   }   int ans[105][105];   void init() {     memset(head, -1, sizeof(head));     memset(ans, 0, sizeof(ans));     lnum = 0;   }   int a[105], b[105];   int main() {     int n, m;     scanf( %d%d , &n, &m);     dic.s = 0, dic.t = 205;     dic.init();     init();     int sum1 = 0, sum2 = 0;     for (int i = 1; i <= n; i++) {       scanf( %d , &a[i]);       sum1 += a[i];     }     for (int i = 1; i <= n; i++) {       scanf( %d , &b[i]);       sum2 += b[i];     }     int A, B;     for (int i = 0; i < m; i++) {       scanf( %d%d , &A, &B);       addline(A, B);       addline(B, A);     }     for (int j = 1; j <= n; j++) {       dic.add(dic.s, j, a[j]);       dic.add(j + 100, dic.t, b[j]);       dic.add(j, j + 100, a[j]);       for (int i = head[j]; ~i; i = ed[i].next) dic.add(j, ed[i].to + 100, a[j]);     }     int k = dic.Maxflow();     if (k == sum1 && k == sum2) {       printf( YES n );       for (int i = 0; i < dic.lnum; i++) {         if (dic.ed[i].from != dic.s && dic.ed[i].to != dic.t &&             dic.ed[i].from <= 100 && dic.ed[i].to > 100) {           ans[dic.ed[i].from][dic.ed[i].to - 100] += dic.ed[i].flow;         }       }       for (int i = 1; i <= n; i++) {         for (int j = 1; j < n; j++) printf( %d  , ans[i][j]);         printf( %d n , ans[i][n]);       }     } else       printf( NO n );   }