#include <bits/stdc++.h>
using namespace std;
const long long INF = 1LL << 60;
bool vis[100005];
int to[200005];
long long deg[100005];
int dep[100005];
vector<int> G[100005];
long long used[200005];
long long rem[100005];
void dfs(int v, int par, int ce) {
  vis[v] = true;
  dep[v] = dep[par] + 1;
  rem[v] = deg[v];
  for (int k = 0; k < (G[v].size()); k++) {
    int e = G[v][k], u = to[e];
    if (u == par || vis[u]) continue;
    dfs(u, v, e ^ 1);
    rem[v] -= used[e];
  }
  if (ce != -1) {
    used[ce] = used[ce ^ 1] = rem[v];
    rem[v] = 0;
  }
}
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int k = 1; k <= (n); k++) scanf("%I64d", &deg[k]);
  for (int k = 0; k < (m); k++) {
    int u, v;
    scanf("%d%d", &u, &v);
    G[u].push_back(k << 1);
    G[v].push_back(k << 1 | 1);
    to[k + k] = v;
    to[k + k + 1] = u;
  }
  memset(vis, false, sizeof(vis));
  dfs(1, 0, -1);
  for (int k = 0; k < (m); k++) {
    int u = to[k << 1], v = to[k << 1 | 1];
    if (used[k << 1] != 0LL || (dep[u] - dep[v]) & 1) continue;
    long long cd = rem[1] >> 1;
    if (!(dep[u] & 1)) cd = -cd;
    used[k << 1] = used[k << 1 | 1] = cd;
    deg[u] -= cd;
    deg[v] -= cd;
    break;
  }
  memset(vis, false, sizeof(vis));
  dfs(1, 0, -1);
  if (rem[1] == 0LL) {
    printf("YES\n");
    for (int k = 0; k < (m); k++) printf("%I64d\n", used[k << 1]);
  } else
    printf("NO\n");
  return 0;
}
