#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 999;
struct edge {
  int to, nxt, from, ban;
  long long dis;
} e[maxn << 1];
int n, c[maxn], head[maxn], tot = -1;
void add(int x, int y) {
  e[++tot].to = y;
  e[tot].from = x;
  e[tot].nxt = head[x];
  head[x] = tot;
}
int vis[maxn], fl, m, dep[maxn], f[maxn];
long long delta;
namespace DSU {
int fa[maxn];
int find(int x) { return fa[x] == x ? x : fa[x] = find(fa[x]); }
}  // namespace DSU
using namespace DSU;
long long dp(int x, int fa) {
  int leaf = 1;
  long long sum = 0;
  dep[x] = dep[fa] + 1;
  f[x] = fa;
  for (int i = head[x]; ~i; i = e[i].nxt) {
    int y = e[i].to;
    if (e[i].ban || y == fa) continue;
    leaf = 0;
    e[i].dis = dp(y, x);
    sum += e[i].dis;
  }
  if (leaf) return c[x];
  return c[x] - sum;
}
int main() {
  scanf("%d%d", &n, &m);
  memset(head, -1, sizeof(head));
  for (int i = 1; i <= n; ++i) scanf("%I64d", &c[i]), fa[i] = i;
  for (int i = 1; i <= m; ++i) {
    int x, y;
    scanf("%d%d", &x, &y);
    add(x, y);
    add(y, x);
  }
  for (int i = 0; i <= tot; i += 2) {
    int x = find(e[i].from), y = find(e[i].to);
    if (x == y)
      e[i].ban = e[i ^ 1].ban = 1;
    else
      fa[x] = y;
  }
  delta = dp(1, 0);
  if (delta & 1) {
    cout << "NO";
    return 0;
  } else if (delta) {
    int x, y, opt;
    for (int i = 0; i <= tot; i += 2)
      if (e[i].ban) {
        x = e[i].to, y = e[i].from;
        if ((dep[x] & 1) == (dep[y] & 1)) {
          opt = (dep[x] - dep[1]) & 1 ? -1 : 1;
          e[i].dis += opt * delta / 2;
          fl = 1;
          break;
        }
      }
    if (!fl) {
      cout << "NO";
      return 0;
    }
    delta /= 2;
    c[x] -= opt * delta;
    c[y] -= opt * delta;
    delta = dp(1, 0);
  }
  printf("YES\n");
  for (int i = 0; i <= tot; i += 2) printf("%I64d\n", e[i].dis + e[i ^ 1].dis);
  return 0;
}
