#include <bits/stdc++.h>
const int N = 100005;
int n, m, head[N], id[N], c[N], tot = 1;
long long weight[N];
struct edge {
  int to, nxt;
} e[N << 1];
int fa[N];
int find(int x) { return x == fa[x] ? x : fa[x] = find(fa[x]); }
void link(int x, int y) {
  e[++tot] = (edge){y, head[x]}, head[x] = tot;
  e[++tot] = (edge){x, head[y]}, head[y] = tot;
}
int f[N], g[N], dep[N];
void dfs(int x) {
  weight[g[x]] = c[x];
  for (int i = head[x]; i; i = e[i].nxt)
    if (e[i].to != f[x]) {
      f[e[i].to] = x, g[e[i].to] = id[i >> 1];
      dep[e[i].to] = dep[x] + 1, dfs(e[i].to);
      weight[g[x]] -= weight[g[e[i].to]];
    }
}
int u[N], v[N];
int main() {
  std::ios::sync_with_stdio(0), std::cin.tie(0);
  std::cin >> n >> m;
  for (int i = 1; i <= n; ++i) fa[i] = i, std::cin >> c[i];
  for (int i = 1; i <= m; ++i) {
    static int cnt = 0;
    std::cin >> u[i] >> v[i];
    if (find(u[i]) != find(v[i])) {
      id[++cnt] = i, link(u[i], v[i]);
      fa[find(u[i])] = find(v[i]);
    }
  }
  dfs(1);
  for (int i = 1; i <= m; ++i)
    if (!(dep[u[i]] - dep[v[i]] & 1)) {
      long long t = weight[0] / 2;
      weight[0] = 0;
      if (dep[u[i]] & 1) t = -t;
      long long s = weight[i] = t;
      for (int j = u[i]; j > 1; j = f[j]) weight[g[j]] += s = -s;
      for (int j = v[i]; j > 1; j = f[j]) weight[g[j]] += t = -t;
      break;
    }
  if (weight[0]) return std::cout << "NO\n", 0;
  std::cout << "YES\n";
  for (int i = 1; i <= m; ++i) std::cout << weight[i] << '\n';
  return 0;
}
