#include <bits/stdc++.h>   using namespace std;   int n, m;   int c[100010];   int x[100010], y[100010];   vector<int> t[100010];   int f[100010];   int find(int x) { return (f[x] == -1 ? x : f[x] = find(f[x])); }   int fa[100010], dep[100010];   int dfn[100010], rnk[100010], totn = 0;   int siz[100010], son[100010], top[100010];   void dfs1(int k) {     dep[k] = dep[fa[k]] + 1;     siz[k] = 1;     for (vector<int>::iterator it = t[k].begin(); it != t[k].end(); ++it) {       if (*it == fa[k]) continue;       fa[*it] = k;       dfs1(*it);       siz[k] += siz[*it];       if (son[k] == 0 || siz[*it] > siz[son[k]]) son[k] = *it;     }     return;   }   void dfs2(int k, int tp) {     dfn[k] = ++totn;     rnk[totn] = k;     top[k] = tp;     if (son[k]) dfs2(son[k], tp);     for (vector<int>::iterator it = t[k].begin(); it != t[k].end(); ++it) {       if (*it == fa[k] || *it == son[k]) continue;       dfs2(*it, *it);     }     return;   }   int LCA(int a, int b) {     while (top[a] != top[b]) {       if (dep[top[a]] < dep[top[b]]) swap(a, b);       a = fa[top[a]];     }     return (dep[a] < dep[b] ? a : b);   }   long long v[100010];   void dfs3(int k) {     v[k] = c[k];     for (vector<int>::iterator it = t[k].begin(); it != t[k].end(); ++it) {       if (*it == fa[k]) continue;       dfs3(*it);       v[k] -= v[*it];     }     return;   }   long long ve[100010];   int main() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; ++i) scanf( %d , &c[i]);     for (int i = 1; i <= m; ++i) scanf( %d%d , &x[i], &y[i]);     memset(f, -1, sizeof(f));     for (int i = 1; i <= m; ++i) {       int p = find(x[i]), q = find(y[i]);       if (p == q) continue;       f[p] = q;       t[x[i]].push_back(y[i]);       t[y[i]].push_back(x[i]);     }     dfs1(1);     dfs2(1, 1);     dfs3(1);     for (int i = 1; i <= m; ++i) {       if (fa[x[i]] == y[i] || fa[y[i]] == x[i]) continue;       if ((dep[x[i]] + dep[y[i]] - 2 * dep[LCA(x[i], y[i])]) % 2 == 0) {         int val = v[1] / 2;         val = val * (dep[x[i]] % 2 == 0 ? -1 : 1);         ve[i] = val;         c[x[i]] -= val;         c[y[i]] -= val;         break;       }     }     dfs3(1);     if (v[1] != 0) {       puts( NO );       return 0;     }     puts( YES );     for (int i = 1; i <= m; ++i) {       if (fa[x[i]] == y[i] || fa[y[i]] == x[i]) {         if (dep[x[i]] < dep[y[i]]) swap(x[i], y[i]);         ve[i] = v[x[i]];       }       printf( %lld n , ve[i]);     }     return 0;   }   