#include <bits/stdc++.h>
using namespace std;
const int maxn = 100009;
struct E {
  int u, v;
  long long val;
} edges[maxn];
vector<int> neigh[maxn];
long long val[maxn];
int be = -1;
int depth[maxn];
long long cur_val[maxn];
void dfs(int v, int p) {
  int bck;
  for (int i : neigh[v]) {
    int u = (edges[i].v == v ? edges[i].u : edges[i].v);
    if (u == p) {
      bck = i;
    } else if (depth[u] == -1) {
      depth[u] = depth[v] + 1;
      dfs(u, v);
    } else if (depth[u] < depth[v]) {
      if ((depth[u] + depth[v]) % 2 == 0) {
        be = i;
      }
    }
  }
  if (v != 1) {
    edges[bck].val = cur_val[v];
    cur_val[p] -= cur_val[v];
  }
}
int main() {
  ios::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= n; i++) cin >> val[i];
  for (int i = 0; i < m; i++) {
    int u, v;
    cin >> u >> v;
    edges[i].u = u;
    edges[i].v = v;
    neigh[u].push_back(i);
    neigh[v].push_back(i);
  }
  memset(depth, -1, sizeof depth);
  memcpy(cur_val, val, sizeof val);
  depth[1] = 0;
  dfs(1, 0);
  if (cur_val[1] != 0) {
    if (be == -1 || cur_val[1] % 2 != 0) {
      cout << "NO";
      return 0;
    }
    for (int i = 0; i < m; i++) edges[i].val = 0;
    if (depth[edges[be].u] % 2 == 0)
      edges[be].val = cur_val[1] / 2;
    else
      edges[be].val = -cur_val[1] / 2;
    val[edges[be].u] -= edges[be].val;
    val[edges[be].v] -= edges[be].val;
    memset(depth, -1, sizeof depth);
    memcpy(cur_val, val, sizeof val);
    depth[1] = 0;
    dfs(1, 0);
  }
  cout << "YES\n";
  for (int i = 0; i < m; i++) cout << edges[i].val << "\n";
}
