#include <bits/stdc++.h>
using namespace std;
const int IINF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fll;
const double DINF = numeric_limits<double>::infinity();
const int MOD = 1000000007;
const double EPS = 1e-9;
const int DX[] = {1, 0, -1, 0, 1, -1, 1, -1};
const int DY[] = {0, 1, 0, -1, 1, -1, -1, 1};
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
long long sqr(long long x) { return x * x; }
long long sqr(int x) { return (long long)x * x; }
double sqr(double x) { return x * x; }
long double sqr(long double x) { return x * x; }
mt19937 mmtw(960172);
long long rnd(long long x, long long y) {
  static uniform_int_distribution<long long> d;
  return d(mmtw) % (y - x + 1) + x;
}
const int N = 100179;
int n, m;
vector<pair<int, int> > e[N];
vector<int> e1[N];
int col[N];
int pred[N];
int predI[N];
long long c[N];
vector<pair<int, int> > edges;
long long ans[N];
void dfs(int v, int cc, int p = -1, int pi = -1) {
  if (col[v] != -1) return;
  col[v] = cc;
  pred[v] = p;
  predI[v] = pi;
  if (p != -1) e1[p].push_back(v);
  for (pair<int, int> nv : e[v]) dfs(nv.first, cc ^ 1, v, nv.second);
}
void dfs2(int v) {
  for (int nv : e1[v]) {
    dfs2(nv);
    long long x = c[nv];
    ans[predI[nv]] += x;
    c[nv] -= x;
    c[v] -= x;
  }
}
int main() {
  ios::sync_with_stdio(false);
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; ++i) scanf("%lld", &c[i]);
  for (int i = 0; i < m; ++i) {
    int x, y;
    scanf("%d%d", &x, &y);
    --x;
    --y;
    e[x].push_back({y, i});
    e[y].push_back({x, i});
    edges.push_back({x, y});
  }
  memset(col, -1, sizeof(col));
  dfs(0, 0, -1);
  long long sum[2] = {0, 0};
  for (int i = 0; i < n; ++i) sum[col[i]] += c[i];
  if ((sum[0] - sum[1]) % 2 != 0) {
    cout << "NO\n";
    return 0;
  }
  if (sum[0] != sum[1]) {
    bool ok = false;
    for (int i = 0; i < m; ++i) {
      int x = edges[i].first;
      int y = edges[i].second;
      if (col[x] == col[y]) {
        ok = true;
        ans[i] = (sum[col[x]] - sum[col[x] ^ 1]) / 2;
        c[x] -= ans[i];
        c[y] -= ans[i];
        break;
      }
    }
    if (!ok) {
      cout << "NO\n";
      return 0;
    }
  }
  dfs2(0);
  cout << "YES\n";
  for (int i = 0; i < m; ++i) cout << ans[i] << "\n";
  return 0;
}
