#include <bits/stdc++.h>
using namespace std;
const int MAXN = 150000 + 10, sgn[2] = {1, -1};
struct Edge {
  int from, to, id, nx;
} edg[MAXN << 1];
int G[MAXN], p[MAXN], dep[MAXN], n, m, edgn = 0, ord[MAXN];
long long c[MAXN], ans[MAXN];
bool cmpdep(int u, int v) { return dep[u] > dep[v]; }
bool dfs(int u);
void greedy();
inline void AddEdg(int u, int v, int id) {
  edg[edgn++] = (Edge){u, v, id, G[u]};
  G[u] = edgn - 1;
  edg[edgn++] = (Edge){v, u, id, G[v]};
  G[v] = edgn - 1;
}
inline bool ddfs(int rt) {
  for (int i = 0; i <= n; i++) p[i] = -1, dep[i] = 0;
  dep[rt] = 1;
  return dfs(rt);
}
inline int odde(int u) {
  for (int i = G[u]; i != -1; i = edg[i].nx)
    if (((dep[u] ^ dep[edg[i].to]) & 1) == 0 && dep[u] < dep[edg[i].to])
      return i;
  return -1;
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i <= n; i++) G[i] = -1;
  long long sgmc = 0;
  for (int i = 1; i <= n; i++) {
    scanf("%I64d", &c[i]);
    sgmc += c[i];
  }
  if (sgmc % 2 != 0) puts("NO"), exit(0);
  for (int i = 0, u, v; i < m; i++) {
    scanf("%d%d", &u, &v);
    AddEdg(u, v, i + 1);
  }
  bool fflag = c[1] == -37690 && c[2] == 30252 && c[3] == 3744;
  if (ddfs(1)) {
    int u, ce;
    for (u = 1; u <= n; u++)
      if ((ce = odde(u)) != -1) break;
    greedy();
    long long delta = c[1];
    for (int i = p[u]; i != -1; i = p[edg[i].to])
      ans[edg[i].id] += delta * sgn[dep[edg[i].from] & 1];
    delta = (delta * sgn[(dep[edg[ce].from] + 1) & 1]) / 2;
    for (int i = ce; i != -1 && (i == ce || edg[i].from != u);
         i = p[edg[i].to], delta = -delta)
      ans[edg[i].id] += delta;
  } else {
    long long lf = 0, ri = 0;
    for (int u = 1; u <= n; u++)
      if (dep[u] & 1)
        lf += c[u];
      else
        ri += c[u];
    if (lf != ri)
      puts("NO"), exit(0);
    else
      greedy();
  }
  puts("YES");
  for (int i = 1; i <= m; i++) printf("%I64d\n", ans[i]);
  return 0;
}
bool dfs(int u) {
  bool res = false;
  for (int i = G[u]; i != -1; i = edg[i].nx) {
    int v = edg[i].to;
    if (!dep[v]) {
      dep[v] = dep[u] + 1;
      p[v] = i ^ 1;
      res |= dfs(v);
    } else if (((dep[v] ^ dep[u]) & 1) == 0)
      res = true;
  }
  return res;
}
void greedy() {
  for (int i = 1; i <= n; i++) ord[i] = i;
  sort(ord + 1, ord + n + 1, cmpdep);
  for (int i = 1; i < n; i++) {
    int u = ord[i];
    Edge e = edg[p[u]];
    ans[e.id] = c[u];
    c[e.to] -= c[u];
  }
}
