#include <bits/stdc++.h>
using namespace std;
int n, m;
long long c[100010];
vector<int> g[100010];
int to[100010 << 1];
long long w[100010];
long long s[2];
int col[100010];
int sp[2];
void dfs(int u, int pa) {
  s[col[u]] += c[u];
  for (int i : g[u]) {
    int v = to[i];
    if (v == pa) continue;
    if (col[v] >= 0) {
      if (col[u] == col[v]) sp[col[u]] = i % m;
    } else {
      col[v] = 1 ^ col[u];
      dfs(v, u);
    }
  }
}
void give_value(int u, int pa = 0) {
  col[u] = 1;
  for (int i : g[u]) {
    int v = to[i];
    if (col[v]) continue;
    give_value(v, u);
    w[i % m] = c[v];
    c[u] -= c[v];
  }
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) scanf("%I64d", &c[i]);
  for (int i = 0, u, v; i < m; i++) {
    scanf("%d%d", &u, &v);
    to[i] = v;
    g[u].push_back(i);
    to[i + m] = u;
    g[v].push_back(i + m);
  }
  for (int i = 1; i <= n; i++) col[i] = -1;
  col[1] = 0;
  sp[0] = sp[1] = -1;
  dfs(1, 0);
  if (sp[0] >= 0) {
    w[sp[0]] = (s[0] - s[1]) / 2;
    c[to[sp[0]]] -= w[sp[0]];
    c[to[sp[0] + m]] -= w[sp[0]];
    s[0] -= 2 * w[sp[0]];
  } else if (sp[1] >= 0) {
    w[sp[1]] = (s[1] - s[0]) / 2;
    c[to[sp[1]]] -= w[sp[1]];
    c[to[sp[1] + m]] -= w[sp[1]];
    s[1] -= 2 * w[sp[1]];
  }
  if (s[0] != s[1])
    puts("NO");
  else {
    memset(col, 0, sizeof col);
    give_value(1);
    assert(c[1] == 0);
    puts("YES");
    for (int i = 0; i < m; i++) printf("%I64d\n", w[i]);
  }
}
