#include <bits/stdc++.h>
using namespace std;
int const N = 100000;
int n, m, x[N + 1], vis[N + 1 << 1], vs, R = 1;
long long an[N];
vector<pair<int, int> > g[N + 1];
bool cl[N + 1];
bool odd(int v = 1, bool c = false) {
  if (vis[v] == vs) {
    if (cl[v] == c) return false;
    R = v;
    return true;
  }
  vis[v] = vs;
  cl[v] = c;
  for (int i = 0; i < (int)(g[v].size()); ++i) {
    int u = g[v][i].first;
    if (odd(u, !c)) return true;
  }
  return false;
}
long long gr(int v = R) {
  vis[v] = vs;
  long long s = 0;
  for (int i = 0; i < (int)(g[v].size()); ++i) {
    int u = g[v][i].first, id = g[v][i].second;
    if (vis[u] == vs) continue;
    long long t = gr(u);
    an[id] += t;
    s += t;
  }
  return x[v] - s;
}
long long Z;
bool go(int v = R, bool p = false) {
  vis[v << 1 | p] = vs;
  if (v == R && p) return true;
  for (int i = 0; i < (int)(g[v].size()); ++i) {
    int u = g[v][i].first, id = g[v][i].second;
    if (vis[u << 1 | p ^ 1] == vs) continue;
    if (go(u, !p)) {
      an[id] += p ? -Z : Z;
      return true;
    }
  }
  return false;
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i < (int)(n + 1); ++i) scanf("%d", x + i);
  for (int i = 0; i < (int)(m); ++i) {
    int a, b;
    scanf("%d%d", &a, &b);
    g[a].push_back(make_pair(b, i));
    g[b].push_back(make_pair(a, i));
  }
  ++vs;
  if (odd()) {
    ++vs;
    Z = gr() >> 1;
    ++vs;
    go();
  } else {
    long long a = 0, b = 0;
    for (int i = 1; i < (int)(n + 1); ++i)
      if (cl[i])
        a += x[i];
      else
        b += x[i];
    if (a != b) {
      printf("NO\n");
      return 0;
    }
    ++vs;
    gr();
  }
  printf("YES\n");
  for (int i = 0; i < (int)(m); ++i) printf("%lld\n", an[i]);
}
