#include <bits/stdc++.h>
using namespace std;
template <class C>
void mini(C &a4, C b4) {
  a4 = min(a4, b4);
}
template <class C>
void maxi(C &a4, C b4) {
  a4 = max(a4, b4);
}
template <class TH>
void _dbg(const char *sdbg, TH h) {
  cerr << sdbg << '=' << h << endl;
}
template <class TH, class... TA>
void _dbg(const char *sdbg, TH h, TA... a) {
  while (*sdbg != ',') cerr << *sdbg++;
  cerr << '=' << h << ',';
  _dbg(sdbg + 1, a...);
}
template <class T>
ostream &operator<<(ostream &os, vector<T> V) {
  os << "[";
  for (auto vv : V) os << vv << ",";
  return os << "]";
}
template <class L, class R>
ostream &operator<<(ostream &os, pair<L, R> P) {
  return os << "(" << P.first << "," << P.second << ")";
}
const long long MAX = 1e5 + 10;
long long n, m;
long long c[MAX];
vector<pair<long long, long long> > d[MAX];
long long res[MAX];
long long s[MAX];
long long par[MAX];
long long pari[MAX];
pair<long long, long long> np = {-1, -1};
long long npi = -1;
bool vis[MAX];
void dfs(long long v, long long gl) {
  vis[v] = 1;
  s[v] = gl;
  for (pair<long long, long long> el : d[v]) {
    if (!vis[el.first]) {
      par[el.first] = v;
      pari[el.first] = el.second;
      dfs(el.first, gl + 1);
      res[el.second] += c[el.first];
      c[v] -= c[el.first];
    } else {
      if (s[v] % 2 == s[el.first] % 2) {
        np = {v, el.first};
        npi = el.second;
      }
    }
  }
}
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout << fixed << setprecision(11);
  if (0) cout << fixed << setprecision(6);
  cin >> n >> m;
  for (long long i = (0); i <= ((long long)(n)-1); i++) cin >> c[i];
  for (long long i = (0); i <= ((long long)(m)-1); i++) {
    res[i] = 1;
    long long a, b;
    cin >> a >> b;
    a--;
    b--;
    c[a]--;
    c[b]--;
    d[a].push_back({b, i});
    d[b].push_back({a, i});
  }
  dfs(0, 0);
  for (long long i = (0); i <= ((long long)(n)-1); i++) {
    if (0) cout << s[i] << " ";
  }
  if (0) cout << "\n";
  if (c[0] != 0) {
    (c[0]);
    for (long long i = (0); i <= ((long long)(m)-1); i++) {
      if (0) cout << res[i] << " ";
    }
    if (0) cout << "\n";
    if (np.first == -1) {
      cout << "NO\n";
      return 0;
    }
    long long zn = 1;
    long long il = c[0] / 2;
    if (s[np.first] % 2 == 1) {
      zn = -1;
    }
    (npi);
    res[npi] += zn * il;
    (res[npi], npi, np);
    for (long long ak : {np.first, np.second}) {
      (ak, il);
      long long x = zn * -1;
      while (ak != 0) {
        res[pari[ak]] += x * il;
        ak = par[ak];
        x *= -1;
      }
    }
  }
  cout << "YES\n";
  for (long long i = (0); i <= ((long long)(m)-1); i++) {
    cout << res[i] << "\n";
  }
}
