#include <bits/stdc++.h>
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC optimize("Ofast")
using namespace std;
inline long long get() {
  long long n = 0;
  char c;
  while ((c = getchar()) || 23333) {
    if (c >= '0' && c <= '9') break;
    if (c == '-') goto s;
  }
  n = c - '0';
  while ((c = getchar()) || 23333) {
    if (c >= '0' && c <= '9')
      n = n * 10 + c - '0';
    else
      return (n);
  }
s:
  while ((c = getchar()) || 23333) {
    if (c >= '0' && c <= '9')
      n = n * 10 - c + '0';
    else
      return (n);
  }
}
typedef struct _b {
  long long dest;
  long long nxt;
  long long num;
} bian;
bian memchi[200001];
long long gn = 1;
long long heads[200001], ints[100001], anss[100001], ss[100001], ts[100001],
    v[100001];
inline void add(long long s, long long t, long long num) {
  memchi[gn].dest = t;
  memchi[gn].nxt = heads[s];
  memchi[gn].num = num;
  heads[s] = gn;
  gn++;
}
unsigned char col[100001];
long long que[100001];
unsigned char istree[100001];
void print(long long num) {
  if (num < 0) putchar('-'), num = -num;
  if (num >= 10) print(num / 10);
  putchar(num % 10 + '0');
}
long long find(long long n) {
  if (ints[n] == n) return (n);
  return (ints[n] = find(ints[n]));
}
void dfs(long long pt, long long baba) {
  for (register long long i = heads[pt]; i; i = memchi[i].nxt) {
    if (memchi[i].dest == baba) continue;
    dfs(memchi[i].dest, pt);
    anss[memchi[i].num] += v[memchi[i].dest];
    v[pt] -= v[memchi[i].dest];
    v[memchi[i].dest] = 0;
  }
}
long long tmp[100001];
void efs(long long pt, long long baba) {
  for (register long long i = heads[pt]; i; i = memchi[i].nxt) {
    if (memchi[i].dest == baba) continue;
    efs(memchi[i].dest, pt);
    tmp[pt] -= tmp[memchi[i].dest];
  }
}
signed main() {
  long long n = get(), m = get();
  for (register long long i = 1; i <= n; i++)
    v[i] = get(), ints[i] = i, col[i] = 2;
  for (register long long i = 1; i <= m; i++) {
    ss[i] = get(), ts[i] = get();
    long long aa = find(ss[i]), ab = find(ts[i]);
    if (aa != ab) {
      ints[aa] = ab;
      add(ss[i], ts[i], i);
      add(ts[i], ss[i], i);
      istree[i] = 1;
    }
  }
  register long long head = 0, tail = 1;
  que[0] = 1;
  col[1] = 0;
  do {
    long long me = que[head];
    head++;
    for (register long long i = heads[me]; i; i = memchi[i].nxt) {
      if (col[memchi[i].dest] != 2) continue;
      col[memchi[i].dest] = col[me] ^ 1;
      que[tail] = memchi[i].dest;
      tail++;
    }
  } while (head < tail);
  dfs(1, 0);
  if (((v[1] < 0) ? -(v[1]) : v[1]) & 1) {
    printf("NO\n");
    return (0);
  }
  if (v[1] == 0) {
    printf("YES\n");
    for (register long long i = 1; i <= m; i++) print(anss[i]), putchar('\n');
    return (0);
  }
  for (register long long a = 1; a <= m; a++) {
    if (istree[a]) continue;
    if (col[ss[a]] != col[ts[a]]) continue;
    printf("YES\n");
    long long val = v[1] / 2;
    tmp[ss[a]]++;
    tmp[ts[a]]++;
    efs(1, 0);
    if (tmp[1] == 2) {
      v[ss[a]] -= val;
      v[ts[a]] -= val;
      anss[a] = val;
    } else {
      v[ss[a]] += val;
      v[ts[a]] += val;
      anss[a] = -val;
    }
    dfs(1, 0);
    for (register long long i = 1; i <= m; i++) print(anss[i]), putchar('\n');
    return (0);
  }
  printf("NO\n");
  return (0);
}
