#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 7;
const int LogN = 18;
template <typename T>
inline T read() {
  T res = 0, flag = 1;
  char in = getchar();
  while (!isdigit(in)) {
    if (in == '-') flag = -1;
    in = getchar();
  }
  while (isdigit(in)) {
    res = (res << 1) + (res << 3) + in - '0';
    in = getchar();
  }
  return res * flag;
}
template <typename T>
inline void chkmax(T &a, T b) {
  if (a < b) a = b;
}
template <typename T>
inline void chkmin(T &a, T b) {
  if (a > b) a = b;
}
namespace DSU {
int f[MAXN];
inline void init() {
  for (int i = 1; i < MAXN; ++i) f[i] = i;
}
inline int find(int first) {
  if (f[first] == first) return first;
  return f[first] = find(f[first]);
}
inline bool inter(int first, int second) { return find(first) == find(second); }
inline void merge(int first, int second) {
  first = find(first);
  second = find(second);
  f[first] = second;
}
}  // namespace DSU
int n, m;
int C[MAXN], dep[MAXN], fa[MAXN];
int f[LogN][MAXN];
pair<int, int> edge[MAXN];
int dex, head[MAXN], nxt[MAXN << 1], to[MAXN << 1], w[MAXN << 1];
bool vis[MAXN];
long long val[MAXN], Req;
inline void Link(int first, int second, int val) {
  nxt[++dex] = head[first];
  to[dex] = second;
  w[dex] = val;
  head[first] = dex;
}
inline long long dfs(int u, int Fa) {
  for (int i = 1; i < LogN; ++i) f[i][u] = f[i - 1][f[i - 1][u]];
  dep[u] = dep[Fa] + 1;
  long long res = C[u];
  for (int i = head[u]; i; i = nxt[i]) {
    int v = to[i];
    if (v == Fa) continue;
    f[0][v] = u;
    fa[v] = w[i];
    val[w[i]] = dfs(v, u);
    res -= val[w[i]];
  }
  return res;
}
inline int check(int first, int second) {
  int res = dep[first] + dep[second];
  int sx = first, sy = second;
  int A;
  if (dep[first] < dep[second]) swap(first, second);
  for (int i = LogN - 1; i >= 0; --i)
    if (dep[f[i][first]] >= dep[second]) first = f[i][first];
  if (first == second)
    A = first;
  else {
    for (int i = LogN - 1; i >= 0; --i)
      if (f[i][first] != f[i][second]) {
        first = f[i][first];
        second = f[i][second];
      }
    A = f[0][first];
  }
  res = res - dep[A] - dep[f[0][A]];
  if (!(res & 1)) return 0;
  return (dep[sx] & 1) ? 1 : -1;
}
inline void Adapt(int first, int second, long long Val) {
  int sav = Val;
  while (first) {
    val[fa[first]] += sav;
    sav = -sav;
    first = f[0][first];
  }
  sav = Val;
  while (second) {
    val[fa[second]] += sav;
    sav = -sav;
    second = f[0][second];
  }
}
inline void init() {
  n = read<int>();
  m = read<int>();
  DSU::init();
  for (int i = 1; i <= n; ++i) C[i] = read<int>();
  for (int i = 1; i <= m; ++i) {
    edge[i].first = read<int>();
    edge[i].second = read<int>();
  }
  for (int i = 1; i <= m; ++i) {
    if (!DSU::inter(edge[i].first, edge[i].second)) {
      DSU::merge(edge[i].first, edge[i].second);
      Link(edge[i].first, edge[i].second, i);
      Link(edge[i].second, edge[i].first, i);
      vis[i] = true;
    }
  }
  Req = dfs(1, 0);
}
inline void solve() {
  if (!Req) {
    printf("YES\n");
    for (int i = 1; i <= m; ++i) printf("%lld\n", val[i]);
    return;
  }
  if (abs(Req) & 1) printf("NO"), exit(0);
  long long tmp;
  for (int i = 1; i <= m; ++i) {
    if (!vis[i]) {
      if (tmp = check(edge[i].first, edge[i].second)) {
        printf("YES\n");
        tmp = tmp * Req / 2;
        val[i] = tmp;
        Adapt(edge[i].first, edge[i].second, -tmp);
        for (int j = 1; j <= m; ++j) {
          printf("%lld\n", val[j]);
        }
        return;
      }
    }
  }
  printf("NO");
}
int main() {
  init();
  solve();
  return 0;
}
