#include <bits/stdc++.h>
int CH, NEG;
template <typename TP>
inline void read(TP& ret) {
  ret = NEG = 0;
  while (CH = getchar(), CH < '!')
    ;
  if (CH == '-') NEG = true, CH = getchar();
  while (ret = ret * 10 + CH - '0', CH = getchar(), CH > '!')
    ;
  if (NEG) ret = -ret;
}
int star[100010LL], e[3][100010LL << 1], te = 1;
inline void AddEdge(int u, int v, int w) {
  te++;
  e[0][te] = v;
  e[1][te] = star[u];
  star[u] = te;
  e[2][te] = w;
  te++;
  e[0][te] = u;
  e[1][te] = star[v];
  star[v] = te;
  e[2][te] = w;
}
int n, m;
long long c[100010LL], cc[100010LL], ans[100010LL];
int pre[100010LL];
bool col[100010LL], vis[100010LL];
bool odd = false;
int eu, ev, ei;
void dfs(int u = 1) {
  vis[u] = true;
  for (int p = star[u], v; p; p = e[1][p])
    if (v = e[0][p], !vis[v]) {
      pre[v] = p;
      col[v] = col[u] ^ 1;
      dfs(v);
      cc[u] -= (ans[e[2][p]] = cc[v]);
    } else if (col[u] == col[v])
      odd = true, eu = u, ev = v, ei = e[2][p];
}
void dfs2(int u) {
  vis[u] = false;
  for (int p = star[u], v; p; p = e[1][p])
    if (v = e[0][p], vis[v] && (col[v] ^ col[u]) && e[2][p] != ei) {
      pre[v] = p;
      dfs2(v);
      c[u] -= (ans[e[2][p]] = c[v]);
    }
}
int main() {
  int i, a, b;
  long long delta, sig;
  read(n), read(m);
  for (i = (1); i <= (n); i++) read(c[i]), cc[i] = c[i];
  for (i = (1); i <= (m); i++) read(a), read(b), AddEdge(a, b, i);
  dfs();
  if (cc[1] == 0) {
    puts("YES");
    for (i = (1); i <= (m); i++) printf("%lld\n", ans[i]);
    goto END;
  }
  if (!odd) {
    puts("NO");
    goto END;
  }
  memset(ans, 0, sizeof ans);
  dfs2(eu);
  delta = c[eu] / 2LL;
  sig = -1LL;
  while (ev != eu) {
    ans[e[2][pre[ev]]] += sig * delta;
    ev = e[0][pre[ev] ^ 1];
    sig *= -1LL;
  }
  ans[ei] += delta;
  puts("YES");
  for (i = (1); i <= (m); i++) printf("%lld\n", ans[i]);
END:
  getchar(), getchar();
  return 0;
}
