2 1
1 1
2 1
 8 12
-6 2 -3 2 6 -7 1 -5
2 1
5 6
1 6
1 4
8 2
2 7
2 5
8 3
8 4
3 7
7 6
3 1
 10 13
3 4 -3 8 6 4 -5 1 3 -7
9 5
9 2
10 3
1 4
3 5
9 1
6 10
10 4
3 1
2 7
1 6
1 7
7 8
 43 52
-23 -18 -35 21 -12 38 -35 -11 28 -20 27 -5 9 -19 -39 -25 -32 32 -36 28 11 37 1 -25 -22 9 -15 21 25 -39 10 36 -30 -40 22 26 25 -27 -22 -38 -1 18 -13
33 40
31 23
30 26
21 17
6 2
41 19
32 39
32 23
13 14
25 35
31 30
19 32
25 22
34 36
7 40
23 6
40 12
1 3
23 43
36 13
18 33
17 32
7 3
21 34
41 35
20 7
23 1
41 8
25 19
20 29
42 5
40 21
9 37
17 41
30 10
41 18
39 1
20 24
20 4
42 3
20 25
5 16
31 9
42 28
10 11
19 42
31 38
25 2
31 27
17 25
13 15
31 20
 2 1
1 1
1 2
 5 7
4 1 5 3 -1
2 4
5 4
5 2
1 5
1 2
4 1
1 3
 10 12
5 1 1 8 -8 10 -3 -2 1 7
5 3
8 2
10 9
4 6
5 6
4 5
5 10
4 7
8 4
3 1
3 6
6 10
 20 40
-9 -10 -9 15 -3 -5 -17 -10 -6 2 -13 19 10 -15 15 -14 17 0 7 -8
3 17
6 18
15 12
2 5
18 3
16 20
6 17
20 10
10 18
9 12
15 3
6 4
15 16
20 6
20 9
9 4
4 8
14 5
11 7
12 11
3 13
14 19
7 17
16 14
19 7
12 13
14 13
13 11
9 14
13 17
8 19
5 20
2 17
2 16
12 5
8 1
20 3
6 2
5 18
13 8

YES
                                                               1
 NO
 YES
                                                              -7
                                                              10
                                                             -16
                                                               3
                                                              13
                                                               0
                                                               4
                                                               5
                                                               0
                                                              -6
                                                               0
                                                               0
                                                               1
 NO
 YES
                                                               1
 YES
                                                               2
                                                               1
                                                              -1
                                                              -1
                                                               0
                                                               0
                                                               5
 YES
-4
1
1
17
-7
-3
6
-3
-3
5
0
0
 YES
                                                             -30
                                                             -21
                                                             -23
                                                             -10
                                                              21
                                                             -52
                                                               0
                                                               2
                                                               0
                                                              -9
                                                               0
                                                              16
                                                              38
                                                               0
                                                              42
                                                               0
                                                              -1
                                                               7
                                                             -64
                                                              51
                                                               0
                                                               7
                                                              47
                                                               0
                                                               0
                                                               0
                                                              10
                                                               0
                                                             -39
                                                               0
                                                               0
                                                               0
                                                               0
                                                               0
                                                               0
                                                              -9
                                                               0
                                                               0
                                                               0
                                                               0

#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 10;
struct Edge {
  int a, b;
  int id;
  void read(int i) {
    id = i;
    scanf("%d%d", &a, &b);
    --a;
    --b;
  }
  int to(int v) const {
    assert(v == a || v == b);
    return (a ^ b) ^ v;
  }
};
int n, m;
vector<int> c;
vector<Edge> g[MAXN];
bool read() {
  if (scanf("%d%d", &n, &m) < 2) {
    return 0;
  }
  for (int i = 0; i < int(n); ++i) {
    g[i].clear();
  }
  c.resize(n);
  for (int i = 0; i < int(n); ++i) {
    scanf("%d", &c[i]);
  }
  for (int i = 0; i < int(m); ++i) {
    Edge e;
    e.read(i);
    g[e.a].push_back(e);
    g[e.b].push_back(e);
  }
  return 1;
}
vector<int> in_tree;
void dfs0(int v, int p, vector<int>& was, vector<int>& depth, int& root) {
  assert(!was[v]);
  was[v] = 1;
  for (const auto& e : g[v]) {
    const int to = e.to(v);
    if (to == p) {
      continue;
    }
    if (was[to]) {
      const int dist = abs(depth[v] - depth[to]);
      if (dist % 2 == 0) {
        root = v;
      }
      continue;
    }
    in_tree[e.id] = 1;
    depth[to] = depth[v] + 1;
    dfs0(to, v, was, depth, root);
  }
}
int getRoot() {
  vector<int> was(n, 0);
  vector<int> depth(n, 0);
  int root = -1;
  dfs0(0, -1, was, depth, root);
  return root;
}
void dfs1(int v, int p, vector<int>& was, vector<long long>& w,
          vector<Edge>& par, vector<int>& depth) {
  assert(!was[v]);
  was[v] = 1;
  long long sum = 0;
  for (const auto& e : g[v]) {
    const int to = e.to(v);
    if (to == p) {
      continue;
    }
    if (was[to]) {
      continue;
    }
    par[to] = e;
    depth[to] = depth[v] + 1;
    dfs1(to, v, was, w, par, depth);
    sum += w[e.id];
  }
  if (par[v].id == -1) {
    assert(p == -1);
    assert(depth[v] == 0);
    const long long diff = c[v] - sum;
    assert(diff % 2 == 0);
    const long long need = diff / 2;
    for (const auto& e : g[v]) {
      const int to = e.to(v);
      const int dist = depth[to];
      assert(dist > 0);
      if (dist % 2 == 1) {
        continue;
      }
      w[e.id] = need;
      int u = to;
      int parity = 1;
      while (u != v) {
        w[par[u].id] += (parity ? -1 : +1) * need;
        parity ^= 1;
        u = par[u].to(u);
      }
      assert(parity == 1);
      {
        for (int u = 0; u < int(n); ++u) {
          long long sum = 0;
          for (const auto& e : g[u]) {
            sum += w[e.id];
          }
          assert(sum == c[u]);
        }
      }
      break;
    }
  } else {
    w[par[v].id] = c[v] - sum;
  }
}
bool solve() {
  in_tree.assign(m, 0);
  int root = getRoot();
  for (int v = 0; v < int(n); ++v) {
    sort(begin(g[v]), end(g[v]), [&](const Edge& e1, const Edge& e2) {
      return in_tree[e1.id] > in_tree[e2.id];
    });
  }
  bool must_ok = 1;
  if (root == -1) {
    must_ok = 0;
    root = 0;
  }
  vector<int> was(n, 0);
  vector<long long> w(m, 0);
  vector<Edge> par(n, Edge{-1, -1, -1});
  vector<int> depth(n, 0);
  dfs1(root, -1, was, w, par, depth);
  for (int v = 0; v < int(n); ++v) {
    long long sum = 0;
    for (const auto& e : g[v]) {
      sum += w[e.id];
    }
    if (sum != c[v]) {
      assert(!must_ok);
      return 0;
    }
  }
  puts("YES");
  for (int i = 0; i < int(m); ++i) {
    printf("%lld\n", w[i]);
  }
  printf("\n");
  return 1;
}
int main() {
  while (read()) {
    if (!solve()) {
      puts("NO");
    }
  }
  return 0;
}
