#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
vector<pair<int, int> > g[N];
long long c[N], cur[N], ans[N];
bool vis[N];
int s = -1, t = -1, idd = -1, col[N], fav[N], d[N], fae[N];
void dfs(int v) {
  vis[v] = true;
  for (int i = 0; i < g[v].size(); i++) {
    int to = g[v][i].first, id = g[v][i].second;
    if (!vis[to]) {
      d[to] = d[v] + 1;
      col[to] = col[v] ^ 1;
      fav[to] = v;
      fae[to] = id;
      dfs(to);
      ans[id] = cur[to];
      cur[v] -= cur[to];
    } else if (d[to] < d[v])
      if (col[to] == col[v]) {
        s = v, t = to;
        idd = id;
      }
  }
}
void sol(int v) {
  vis[v] = true;
  for (int i = 0; i < g[v].size(); i++) {
    int to = g[v][i].first, id = g[v][i].second;
    if (id != idd && !vis[to]) {
      sol(to);
      ans[id] = c[to];
      c[v] -= c[to];
    }
  }
}
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; i++) {
    scanf("%lld", &c[i]);
    cur[i] = c[i];
  }
  for (int i = 0; i < m; i++) {
    int a, b;
    scanf("%d%d", &a, &b);
    a--, b--;
    g[a].push_back(make_pair(b, i));
    g[b].push_back(make_pair(a, i));
  }
  dfs(0);
  if (cur[0] == 0) {
    puts("YES");
    for (int i = 0; i < m; i++) printf("%lld\n", ans[i]);
    return 0;
  }
  if (idd != -1) {
    for (int i = 0; i < m; i++) ans[i] = 0;
    for (int i = 0; i < n; i++) vis[i] = 0;
    sol(s);
    long long res = c[s] / 2;
    int cur = s, sign = 1;
    for (; cur != t; cur = fav[cur]) {
      ans[fae[cur]] += sign * res;
      sign *= -1;
    }
    ans[idd] += sign * res;
    puts("YES");
    for (int i = 0; i < m; i++) printf("%lld\n", ans[i]);
  } else
    puts("NO");
  return 0;
}
