#include <bits/stdc++.h>
using namespace std;
int n, m, tot;
int u[200005], v[200005], on_tree[200005], fa[200005], col[200005],
    fath[200005], dep[200005];
long long c[200005], mk[200005];
vector<int> G[200005];
unordered_map<int, unordered_map<int, long long> > val;
inline int read() {
  int x = 0, f = 1;
  char ch = getchar();
  while (!isdigit(ch)) {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (isdigit(ch)) {
    (x *= 10) += ch - '0';
    ch = getchar();
  }
  return x * f;
}
inline void add_edge(int u, int v) {
  G[u].push_back(v);
  G[v].push_back(u);
}
int findf(int x) { return x == fa[x] ? x : fa[x] = findf(fa[x]); }
void kruskal() {
  for (int i = 1; i <= n; i++) fa[i] = i;
  for (int i = 1; i <= m; i++) {
    if (tot == n - 1) return;
    int uf = findf(u[i]), vf = findf(v[i]);
    if (uf == vf) continue;
    on_tree[i] = 1;
    add_edge(u[i], v[i]);
    tot++;
    fa[uf] = vf;
  }
}
void dfs1(int u, int c_fa, int c_col) {
  col[u] = c_col;
  fath[u] = c_fa;
  dep[u] = dep[c_fa] + 1;
  for (int v : G[u]) {
    if (v == c_fa) continue;
    dfs1(v, u, c_col ^ 1);
    c[u] -= val[u][v];
  }
  val[u][c_fa] = val[c_fa][u] = c[u];
}
void work(int _x, int _y) {
  int x = _x, y = _y;
  int dis = 0, delta = 0, flag = -1;
  if (dep[x] < dep[y]) swap(x, y);
  while (dep[x] > dep[1]) dis++, x = fath[x];
  if (dis & 1)
    delta = -c[1] / 2;
  else
    delta = c[1] / 2;
  x = _x, y = _y;
  if (dep[x] < dep[y]) swap(x, y);
  while (dep[x] > dep[y]) {
    val[x][fath[x]] += flag * delta, val[fath[x]][x] += flag * delta;
    flag = -flag, x = fath[x];
  }
  while (dep[x] > dep[1]) {
    val[x][fath[x]] += flag * delta, val[fath[x]][x] += flag * delta;
    val[y][fath[y]] += flag * delta, val[fath[y]][y] += flag * delta;
    flag = -flag, x = fath[x], y = fath[y];
  }
  val[_x][_y] = val[_y][_x] = delta;
}
int main() {
  n = read(), m = read();
  for (int i = 1; i <= n; i++) c[i] = read();
  for (int i = 1; i <= m; i++) u[i] = read(), v[i] = read();
  kruskal();
  dfs1(1, 0, 1);
  if (c[1] == 0) {
    puts("YES");
    for (int i = 1; i <= m; i++) printf("%lld\n", val[u[i]][v[i]]);
    return 0;
  }
  if (c[1] & 1) {
    puts("NO");
    return 0;
  }
  for (int i = 1; i <= m; i++) {
    if (col[u[i]] != col[v[i]] || on_tree[i]) continue;
    puts("YES");
    work(u[i], v[i]);
    for (int i = 1; i <= m; i++) printf("%lld\n", val[u[i]][v[i]]);
    return 0;
  }
  puts("NO");
  return 0;
}
