#include <bits/stdc++.h>
using namespace std;
const long long MAXN = (long long)1e6 + 3;
const long long infint = (long long)1e9 + 3;
const long long MOD = (long long)1e9 + 7;
const long long inf = (long long)1e18 + 3;
long long n, m, c[MAXN], par[MAXN], visited[MAXN], h[MAXN], edge_1[MAXN],
    edge_2[MAXN];
map<pair<long long, long long>, long long> M;
vector<long long> G[MAXN];
void bfs(long long u) {
  queue<long long> q;
  q.push(u);
  visited[u] = 1;
  while (!q.empty()) {
    long long st = q.front();
    q.pop();
    for (auto v : G[st])
      if (!visited[v]) par[v] = st, visited[v] = 1, h[v] = h[st] + 1, q.push(v);
  }
}
long long dfs(long long u) {
  long long ans = 0;
  for (auto v : G[u])
    if (!visited[v]) visited[v] = 1, M[{u, v}] = dfs(v), ans += M[{u, v}];
  return c[u] - ans;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  for (long long i = 1; i <= n; i++) cin >> c[i];
  for (long long i = 0; i < m; i++) {
    long long u, v;
    cin >> u >> v;
    edge_1[i] = u, edge_2[i] = v;
    G[u].push_back(v);
    G[v].push_back(u);
  }
  bfs(1);
  long long a = -1, b = -1;
  for (long long i = 1; i <= n; i++)
    for (auto u : G[i])
      if (h[i] == h[u]) a = i, b = u;
  if (a != -1) {
    vector<long long> cyc;
    long long lca = -1, tmp_a = a, tmp_b = b;
    while (a != b) {
      if (h[a] > h[b])
        a = par[a];
      else
        b = par[b];
    }
    lca = a;
    a = tmp_a, b = tmp_b;
    while (a != lca) {
      cyc.push_back(a);
      a = par[a];
    }
    vector<long long> sec;
    while (b != lca) {
      sec.push_back(b);
      b = par[b];
    }
    reverse(sec.begin(), sec.end());
    cyc.push_back(lca);
    for (auto u : sec) cyc.push_back(u);
    memset(visited, 0, sizeof visited);
    for (auto u : cyc) visited[u] = 1;
    for (auto u : cyc) c[u] = dfs(u);
    long long ans = 0;
    for (long long i = 0; i < (long long)cyc.size(); i++)
      if (i <= 1)
        ans += c[cyc[i]];
      else if (i % 2 == 0)
        ans -= c[cyc[i]];
      else
        ans += c[cyc[i]];
    M[{cyc[0], cyc[1]}] = ans / 2;
    for (long long i = 1; i < (long long)cyc.size(); i++)
      ans = ans * -1 + 2 * c[cyc[i]],
      M[{cyc[i], cyc[(i + 1) % (long long)cyc.size()]}] = ans / 2;
    cout << "YES\n";
    for (long long i = 0; i < m; i++)
      cout << M[{edge_1[i], edge_2[i]}] + M[{edge_2[i], edge_1[i]}] << "\n";
    return 0;
  }
  memset(visited, 0, sizeof visited);
  visited[1] = 1;
  long long x = dfs(1);
  if (x) return cout << "NO", 0;
  cout << "YES\n";
  for (long long i = 0; i < m; i++)
    cout << M[{edge_1[i], edge_2[i]}] + M[{edge_2[i], edge_1[i]}] << "\n";
}
