#include <bits/stdc++.h>
using namespace std;
int n, m;
vector<int> g[100000];
long long c[100000];
long long w[100000];
int uu[100000], vv[100000];
int col[100000];
int st[100000], sz = 0;
vector<int> cyc;
int cycv = 0;
bool flag = true;
bool dfs(int v, int co) {
  st[sz++] = v;
  col[v] = co;
  for (int e : g[v]) {
    int to = (uu[e] == v ? vv[e] : uu[e]);
    if (col[to] == -1) {
      if (dfs(to, co ^ 1)) {
        if (flag) {
          cyc.push_back(e);
          if (v == cycv) {
            flag = false;
          }
        }
        return true;
      }
    } else if (col[to] == col[v] && cyc.empty()) {
      cyc.push_back(e);
      cycv = to;
      flag = true;
      return true;
    }
  }
  --sz;
  return false;
}
bool used[100000] = {};
void solve(int v) {
  used[v] = true;
  for (int e : g[v]) {
    int to = (uu[e] == v ? vv[e] : uu[e]);
    if (used[to]) {
      continue;
    }
    solve(to);
    w[e] = -c[to];
    c[to] += w[e];
    c[v] += w[e];
  }
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < (int)(n); ++i) scanf("%I64d", c + i), c[i] *= -1;
  for (int i = 0; i < (int)(m); ++i) {
    scanf("%d%d", uu + i, vv + i), --uu[i], --vv[i];
    g[uu[i]].push_back(i);
    g[vv[i]].push_back(i);
  }
  memset(col, -1, sizeof col);
  dfs(0, 0);
  solve(cycv);
  if (c[cycv] != 0) {
    if (cyc.empty()) {
      cout << "NO" << endl;
      return 0;
    }
    long long need = -c[cycv] / 2;
    for (int x : cyc) {
      w[x] += need;
      need *= -1;
    }
  }
  cout << "YES" << endl;
  for (int i = 0; i < (int)(m); ++i) printf("%I64d\n", w[i]);
  return 0;
}
