#include <bits/stdc++.h>
using namespace std;
namespace networks {
class Network {
 public:
  Network(const std::vector<std::pair<int, int>>& flat_edges,
          const std::vector<int>& capacity);
  struct Edge_network_data {
    explicit Edge_network_data() = default;
    Edge_network_data(int from_, int to_, int capacity_, int flow_, int id_,
                      int reverse_id_)
        : from(from_),
          to(to_),
          capacity(capacity_),
          flow(flow_),
          id(id_),
          reverse_id(reverse_id_) {}
    int from, to, capacity, flow, id, reverse_id;
  };
  int max_flow(int source, int sink);
  std::vector<std::vector<int>> edges_ids;
  std::vector<Edge_network_data> data_by_id;
  std::vector<int> augmenting_path_(int source, int sink);
  int additional_flow(const std::vector<int>& path);
  void push_flow(const std::vector<int>& path, int residual_flow);
};
}  // namespace networks
networks::Network::Network(const std::vector<std::pair<int, int>>& flat_edges,
                           const std::vector<int>& capacity) {
  int nodes_count = 0;
  int edges_count = 2 * static_cast<int>(flat_edges.size());
  for (auto [start, end] : flat_edges) {
    nodes_count = std::max(nodes_count, std::max(start, end) + 1);
  }
  edges_ids.resize(nodes_count);
  data_by_id.reserve(edges_count);
  for (int id = 0; id < edges_count; id += 2) {
    auto [start, end] = flat_edges[id / 2];
    edges_ids[start].push_back(id);
    edges_ids[end].push_back(id + 1);
    data_by_id.emplace_back(start, end, capacity[id / 2], 0, id, id + 1);
    data_by_id.emplace_back(end, start, 0, 0, id + 1, id);
  }
}
int networks::Network::max_flow(int source, int sink) {
  for (auto& edge_data : data_by_id) {
    edge_data.flow = 0;
  }
  int flow = 0;
  while (true) {
    auto path = augmenting_path_(source, sink);
    if (path.empty()) {
      break;
    }
    auto residual_flow = additional_flow(path);
    flow += residual_flow;
    push_flow(path, residual_flow);
  }
  return flow;
}
int networks::Network::additional_flow(const std::vector<int>& path) {
  int flow = INT_MAX;
  for (const auto edge_id : path) {
    flow =
        std::min(flow, data_by_id[edge_id].capacity - data_by_id[edge_id].flow);
  }
  return flow;
}
void networks::Network::push_flow(const std::vector<int>& path,
                                  int residual_flow) {
  for (auto edge_id : path) {
    data_by_id[edge_id].flow += residual_flow;
    auto reverse_id = data_by_id[edge_id].reverse_id;
    data_by_id[reverse_id].flow -= residual_flow;
  }
}
std::vector<int> networks::Network::augmenting_path_(int source, int sink) {
  auto nodes_count = static_cast<int>(edges_ids.size());
  std::vector<int> path;
  std::vector<int> ancestors(nodes_count, -1);
  std::queue<int> nodes;
  nodes.push(source);
  while (!nodes.empty()) {
    auto current_node = nodes.front();
    nodes.pop();
    for (auto edge_id : edges_ids[current_node]) {
      auto out_node = data_by_id[edge_id].to;
      if (data_by_id[edge_id].flow == data_by_id[edge_id].capacity) {
        continue;
      }
      if (ancestors[out_node] != -1 || out_node == source) {
        continue;
      }
      ancestors[out_node] = edge_id;
      nodes.push(out_node);
    }
  }
  if (ancestors[sink] != -1) {
    auto current_node = sink;
    while (current_node != source) {
      auto edge_id = ancestors[current_node];
      path.push_back(edge_id);
      current_node = data_by_id[edge_id].from;
    }
  }
  return path;
}
void one_case() {
  int n, m;
  cin >> n >> m;
  vector<pair<int, int>> flat;
  vector<int> capacity(2 * n);
  for (auto& el : capacity) {
    cin >> el;
  }
  for (int i = 0; i < n; ++i) {
    flat.emplace_back(2 * n, i);
  }
  for (int i = 0; i < n; ++i) {
    flat.emplace_back(n + i, 2 * n + 1);
  }
  for (int i = 0; i < m; ++i) {
    int a, b;
    cin >> a >> b;
    --a;
    --b;
    flat.emplace_back(a, n + b);
    flat.emplace_back(b, n + a);
    capacity.push_back(1e9);
    capacity.push_back(1e9);
  }
  for (int i = 0; i < n; ++i) {
    flat.emplace_back(i, i + n);
    capacity.push_back(1e9);
  }
  auto total = accumulate(capacity.begin() + n, capacity.begin() + 2 * n, 0);
  auto was = accumulate(capacity.begin(), capacity.begin() + n, 0);
  networks::Network net(flat, capacity);
  auto flow = net.max_flow(2 * n, 2 * n + 1);
  if (flow == total && total == was) {
    cout << "YES\n";
    for (int i = 0; i < n; ++i) {
      vector<int> out(n);
      for (auto edge_id : net.edges_ids[i]) {
        if (edge_id % 2 == 0) {
          auto to = net.data_by_id[edge_id].to - n;
          out[to] = net.data_by_id[edge_id].flow;
        }
      }
      for (auto el : out) {
        cout << el << " ";
      }
      cout << "\n";
    }
  } else {
    cout << "NO\n";
  }
}
int main() {
  int t = 1;
  while (t--) {
    one_case();
  }
  return 0;
}
