#include <bits/stdc++.h>
using namespace std;
bool debug = 0;
int n, m, k;
int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};
string direc = "RDLU";
long long ln, lk, lm;
void etp(bool f = 0) {
  puts(f ? "YES" : "NO");
  exit(0);
}
void addmod(int &x, int y, int mod = 1000000007) {
  assert(y >= 0);
  x += y;
  if (x >= mod) x -= mod;
  assert(x >= 0 && x < mod);
}
void et() {
  puts("-1");
  exit(0);
}
long long fastPow(long long x, long long y, int mod = 1000000007) {
  long long ans = 1;
  while (y > 0) {
    if (y & 1) ans = (x * ans) % mod;
    x = x * x % mod;
    y >>= 1;
  }
  return ans;
}
long long gcd1(long long x, long long y) {
  long long z = y;
  while (x % y != 0) {
    z = x % y;
    x = y;
    y = z;
  }
  return z;
}
vector<pair<int, int> > mp[100005];
int C[100005], U[100005], V[100005], dp[100005], fa[100005], A, B, AB,
    efa[100005];
long long sv[100005];
long long wt[100005];
bool vis[100005];
void dfs(int x, int pa) {
  vis[x] = 1;
  dp[x] = dp[pa] + 1;
  fa[x] = pa;
  for (auto cp : mp[x])
    if (cp.first != pa) {
      int c = cp.first, eid = cp.second;
      if (vis[c]) {
        if (dp[x] > dp[c] && (dp[x] - dp[c]) % 2 == 0) {
          A = x;
          B = c;
          AB = eid;
        }
      } else {
        efa[c] = eid;
        dfs(c, x);
        wt[eid] = C[c] - sv[c];
        sv[x] += wt[eid];
      }
    }
}
void fmain(int ID) {
  scanf("%d%d", &n, &m);
  for (int(i) = 1; (i) <= (int)(n); (i)++) scanf("%d", C + i);
  for (int i = 1, u, v; i <= m; i++) {
    scanf("%d%d", &u, &v);
    mp[u].push_back({v, i});
    mp[v].push_back({u, i});
    U[i] = u;
    V[i] = v;
  }
  dfs(1, 0);
  if (abs(C[1] - sv[1]) % 2 == 1) etp();
  if (abs(C[1] - sv[1]) != 0) {
    if (A == 0) etp();
    int fg = (dp[B] - dp[1]) & 1 ? -1 : 1;
    long long w = (C[1] - sv[1]) / 2 * fg;
    wt[AB] = w;
    long long tw = w;
    for (int i = A; i != B; i = fa[i]) {
      wt[efa[i]] -= tw;
      tw *= -1;
    }
    tw = w + w;
    for (int i = B; i != 1; i = fa[i]) {
      wt[efa[i]] -= tw;
      tw *= -1;
    }
  }
  puts("YES");
  for (int(i) = 1; (i) <= (int)(m); (i)++) printf("%lld\n", wt[i]);
}
int main() {
  int t = 1;
  for (int(i) = 1; (i) <= (int)(t); (i)++) {
    fmain(i);
  }
  return 0;
}
