#include <bits/stdc++.h>
using namespace std;
const int maxn = 3e5 + 14;
int n, m;
struct Edge {
  int v, u;
  long long w;
  int o(int x) { return x == v ? u : v; }
} e[maxn];
vector<Edge*> g[maxn];
vector<Edge*> cyc, cur;
Edge* par[maxn];
int col[maxn];
long long c[maxn];
int mark[maxn];
bool dfs(int v = 0, int c = 1) {
  col[v] = c;
  mark[v] = cur.size() + 1;
  for (auto e : g[v]) {
    int u = e->o(v);
    if (!col[u]) {
      par[u] = e;
      cur.push_back(e);
      if (dfs(u, 3 - c)) return 1;
      cur.pop_back();
    } else if (col[u] == c) {
      cyc.push_back(e);
      while (!mark[u]) cyc.push_back(par[u]), u = par[u]->o(u);
      while (u != v) {
        cyc.push_back(cur[mark[u] - 1]), u = cur[mark[u] - 1]->o(u);
      }
      return 1;
    }
  }
  mark[v] = 0;
  return 0;
}
void fix(int v, int p = -1) {
  mark[v] = 1;
  for (auto e : g[v]) {
    int u = e->o(v);
    if (!mark[u]) {
      fix(u, v);
      e->w = c[u];
      c[v] -= c[u];
    }
  }
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0);
  cin >> n >> m;
  for (int i = 0; i < n; i++) cin >> c[i];
  for (int i = 0; i < m; i++) {
    cin >> e[i].v >> e[i].u;
    e[i].v--, e[i].u--;
    g[e[i].v].push_back(&e[i]);
    g[e[i].u].push_back(&e[i]);
  }
  int root = 0;
  bool hasCy = 0;
  if (dfs()) {
    root = -1;
    for (auto x : {cyc[0]->v, cyc[0]->u})
      for (auto y : {cyc.back()->v, cyc.back()->u})
        if (x == y) root = x;
    assert(root != -1);
    hasCy = 1;
  }
  memset(mark, 0, sizeof mark);
  fix(root);
  if (hasCy) {
    long long x = c[root] / 2;
    c[root] = 0;
    for (int i = 0; i < cyc.size(); i++) cyc[i]->w += (i & 1 ? -x : x);
  }
  if (!c[root]) {
    cout << "YES\n";
    for (int i = 0; i < m; i++) cout << e[i].w << '\n';
  } else
    cout << "NO\n";
}
