#include <bits/stdc++.h>
using namespace std;
template <typename T1, typename T2>
inline void chkmin(T1 &x, T2 y) {
  if (x > y) x = y;
}
template <typename T1, typename T2>
inline void chkmax(T1 &x, T2 y) {
  if (x < y) x = y;
}
inline int readChar();
template <class T = int>
inline T readInt();
template <class T>
inline void writeInt(T x, char end = 0);
inline void writeChar(int x);
inline void writeWord(const char *s);
static const int buf_size = 4096;
inline int getChar() {
  static char buf[buf_size];
  static int len = 0, pos = 0;
  if (pos == len) {
    pos = 0, len = fread(buf, 1, buf_size, stdin);
  }
  if (pos == len) {
    return -1;
  }
  return buf[pos++];
}
inline int readChar() {
  int c = getChar();
  while (c <= 32) {
    c = getChar();
  }
  return c;
}
template <class T>
inline T readInt() {
  int s = 1, c = readChar();
  T x = 0;
  if (c == '-') s = -1, c = getChar();
  while ('0' <= c && c <= '9') x = x * 10 + c - '0', c = getChar();
  return s == 1 ? x : -x;
}
static int write_pos = 0;
static char write_buf[buf_size];
inline void writeChar(int x) {
  if (write_pos == buf_size)
    fwrite(write_buf, 1, buf_size, stdout), write_pos = 0;
  write_buf[write_pos++] = x;
}
template <class T>
inline void writeInt(T x, char end) {
  if (x < 0) writeChar('-'), x = -x;
  char s[24];
  int n = 0;
  while (x || !n) s[n++] = '0' + x % 10, x /= 10;
  while (n--) writeChar(s[n]);
  if (end) writeChar(end);
}
inline void writeWord(const char *s) {
  while (*s) writeChar(*s++);
}
struct Flusher {
  ~Flusher() {
    if (write_pos) fwrite(write_buf, 1, write_pos, stdout), write_pos = 0;
  }
} flusher;
const string FILENAME = "input";
const int MAXN = 100001;
int n, m;
vector<int> g[MAXN];
long long c[MAXN];
int used[MAXN];
int pr[MAXN];
int edge[MAXN][2];
long long ans[MAXN];
vector<int> cycle;
int inv(int id, int u) { return u ^ edge[id][0] ^ edge[id][1]; }
int dfs1(int v) {
  for (auto h : g[v]) {
    int u = inv(h, v);
    if (used[u] != -1) {
      if (used[v] == used[u]) {
        cycle.push_back(h);
        int w = v;
        while (w != u) {
          cycle.push_back(pr[w]);
          w = inv(pr[w], w);
        }
        return u;
      }
      continue;
    }
    used[u] = used[v] ^ 1;
    pr[u] = h;
    int w = dfs1(u);
    if (w != -1) {
      return w;
    }
  }
  return -1;
}
void dfs2(int v) {
  for (auto h : g[v]) {
    int u = inv(h, v);
    if (pr[u] != -1) {
      continue;
    }
    pr[u] = h;
    dfs2(u);
    ans[h] += c[u];
    c[v] -= c[u];
  }
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    cin >> c[i];
  }
  for (int i = 0; i < m; i++) {
    cin >> edge[i][0] >> edge[i][1];
    edge[i][0]--;
    edge[i][1]--;
    g[edge[i][0]].push_back(i);
    g[edge[i][1]].push_back(i);
  }
  for (int i = 0; i < n; i++) {
    used[i] = -1;
  }
  used[0] = 0;
  int s = dfs1(0);
  for (int i = 0; i < n; i++) {
    pr[i] = -1;
  }
  if (s == -1) {
    pr[0] = -2;
    dfs2(0);
  } else {
    pr[s] = -2;
    dfs2(s);
  }
  if (s == -1 && c[0] != 0) {
    cout << "NO\n";
    return 0;
  }
  chkmax(s, 0);
  for (int i = 0; i < (int)(cycle).size(); i++) {
    if (i & 1) {
      ans[cycle[i]] -= c[s] / 2;
    } else {
      ans[cycle[i]] += c[s] / 2;
    }
  }
  cout << "YES\n";
  for (int i = 0; i < m; i++) {
    cout << ans[i] << '\n';
  }
  return 0;
}
