#include <bits/stdc++.h>
using namespace std;
long long ans[100010];
struct Edge {
  int v, nxt;
} e[200010];
int tot = 1;
int first[100010];
void build(int u, int v) {
  e[++tot] = (Edge){v, first[u]};
  first[u] = tot;
  return;
}
long long c[100010];
int dep[100010];
int sta[100010], head;
bool flag;
int S, x[100010], cnt;
void dfs(int u, int lst) {
  dep[u] = dep[lst] + 1;
  for (int i = first[u]; i; i = e[i].nxt) {
    int v = e[i].v;
    if (v == lst) continue;
    if (!dep[v]) {
      sta[++head] = i / 2;
      dfs(v, u);
      head--;
    } else if (!flag && (dep[u] - dep[v]) % 2 == 0) {
      cnt = dep[u] - dep[v] + 1;
      for (int j = 1; j < cnt; j++) x[j] = sta[head - j + 1];
      x[cnt] = i / 2;
      S = u;
      flag = true;
    }
  }
  return;
}
bool vis[100010];
void solve(int u) {
  vis[u] = true;
  for (int i = first[u]; i; i = e[i].nxt) {
    int v = e[i].v;
    if (vis[v]) continue;
    solve(v);
    ans[i / 2] -= c[v];
    c[u] -= c[v];
  }
  return;
}
int main() {
  int n, m;
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= n; i++) {
    scanf("%I64d", &c[i]);
    c[i] = -c[i];
  }
  for (int i = 1; i <= m; i++) {
    int u, v;
    scanf("%d %d", &u, &v);
    build(u, v);
    build(v, u);
  }
  dfs(1, 0);
  if (flag) {
    solve(S);
    for (int i = 1; i <= cnt; i++)
      if (i & 1)
        ans[x[i]] -= c[S] / 2;
      else
        ans[x[i]] += c[S] / 2;
    printf("YES\n");
    for (int i = 1; i <= m; i++) printf("%I64d\n", ans[i]);
  } else {
    solve(1);
    if (c[1])
      printf("NO\n");
    else {
      printf("YES\n");
      for (int i = 1; i <= m; i++) printf("%I64d\n", ans[i]);
    }
  }
  return 0;
}
