#include <bits/stdc++.h>
using namespace std;
#define PB push_back
#define ZERO (1e-10)
#define INF int(1e9+1)
#define CL(A,I) (memset(A,I,sizeof(A)))
#define DEB printf("DEB!\n");
#define D(X) cout<<"  "<<#X": "<<X<<endl;
#define EQ(A,B) (A+ZERO>B&&A-ZERO<B)
typedef long long ll;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<ii> vii;
#define IN(n) int n;scanf("%d",&n);
#define FOR(i, m, n) for (int i(m); i < n; i++)
#define F(n) FOR(i,0,n)
#define FF(n) FOR(j,0,n)
#define FT(m, n) FOR(k, m, n)
#define aa first
#define bb second
void ga(int N,int *A){F(N)scanf("%d",A+i);}
#define MX 100005
vii g[MX],G[MX];
int N,M,a,b,C[MX],D[MX],X[MX],O[MX],E[MX],t[MX],R=-1,w,v,l,K[MX],H;
void go(int u){if(~E[u])go(t[u]),K[l++]=E[u];}
void clr(int u,int c){
    X[u]=c;
    for(auto&h:g[u])
        if(!X[h.aa])E[u]=h.bb,t[u]=h.aa,G[u].PB(h),G[h.aa].PB({u,h.bb}),clr(h.aa,-c);
        else if(X[h.aa]==c){
            E[u]=-1;
            if(!~R)R=t[h.aa],go(h.aa),K[l++]=h.bb;
            //TODO ELSE WHAT?
        }
}
int dfs(int u,int p,int I){
    for(auto&h:G[u])if(h.aa^p)C[u]-=dfs(h.aa,u,h.bb);
    return O[I]=C[u],C[u];
}
int main(void){
    scanf("%d%d",&N,&M),ga(N,C),memcpy(D,C,sizeof(D));
    F(M)scanf("%d%d",&a,&b),g[--a].PB({--b,i}),g[b].PB({a,i});
    clr(0,1),H=C[max(R,0)],a=dfs(max(R,0),-1,MX-1);
    H=-a;
    if(~R){
        O[*K]-=H/2,O[K[1]]-=H/2;
        FT(2,l)O[K[k]]+=k&1?-H/2:H/2;
    }
    F(N){
        for(auto&h:g[i])D[i]-=O[h.bb];
        if(D[i])return puts("NO");
    }
    puts("YES");
    F(M)printf("%d\n",O[i]);
    return 0;
}//Not correct ..but on some way.. :D


/*
PROG: cf901d
LANG: C++11
    _____
  .'     '.
 /  0   0  \
|     ^     |
|  \     /  |
 \  '---'  /
  '._____.'
 */
#include <bits/stdc++.h>

using namespace std;

long long readi()
{
	long long input = 0;
	char c = ' ';
	while (c < '-')
	{
		c = getchar();
	}
	bool negative = false;
	if (c == '-')
	{
		negative = true;
		c = getchar();
	}
	while (c >= '0')
	{
		input = 10 * input + (c - '0');
		c = getchar();
	}
	if (negative)
	{
		input = -input;
	}
	return input;
}
void printi(long long output)
{
	if (output == 0)
	{
		putchar('0');
		return;
	}
	if (output < 0)
	{
		putchar('-');
		output = -output;
	}
	int aout[20];
	int ilen = 0;
	while(output)
	{
		aout[ilen] = ((output % 10));
		output /= 10;
		ilen++;
	}
	for (int i = ilen - 1; i >= 0; i--)
	{
		putchar(aout[i] + '0');
	}
	return;
}
string reads()
{
	string input = "";
	char c = ' ';
	while (c <= ' ')
	{
		c = getchar();
	}
	while (c > ' ')
	{
		input += c;
		c = getchar();
	}
	return input;
}
int sgn(long long x)
{
	if (x < 0)
	{
		return -1;
	}
	if (x > 0)
	{
		return 1;
	}
	return 0;
}
long long randomize(long long mod)
{
	return ((1 << 30) * rand() + (1 << 15) * rand() + rand()) % mod;
}

#define MP make_pair
#define PB push_back
#define PF push_front
#define LB lower_bound
#define UB upper_bound
#define fi first
#define se second

const long double PI = 4.0 * atan(1.0);
const long double EPS = 1e-30;

#define SINF 10007
#define CO 1000007
#define INF 1000000007
#define BIG 1000000931
#define LARGE 1696969696967ll
#define GIANT 2564008813937411ll
#define LLINF 2696969696969696969ll
#define MAXN 100010

long long normalize(long long x, long long mod)
{
	return (((x % mod) + mod) % mod);
}

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

int N, M;
map<int, int> mp[MAXN];
vector<int> edge[MAXN];
ll arr[MAXN];
ll ans[MAXN];
bool bipartite = true;
bool seen[MAXN], color[MAXN], in[MAXN];
int parent[MAXN];
ll pref[MAXN], suf[MAXN];
vector<int> cyc, nodes;
ll tot;

void dfs(int u, int par, bool col)
{
	if (seen[u])
	{
		if (col != color[u])
		{
			bipartite = false;
			while(nodes.back() != u)
			{
				cyc.PB(nodes.back());
				in[nodes.back()] = true;
//				cerr << nodes.back() << endl;
				nodes.pop_back();
			}
			in[u] = true;
			cyc.PB(u);
//						cerr << u << endl;
		}
		return;
	}
	nodes.PB(u);
	seen[u] = true;
	color[u] = col;
	for (int v : edge[u])
	{
		if (v == par)
		{
			continue;
		}
		dfs(v, u, !col);
		if (!bipartite)
		{
			return;
		}
	}
	nodes.pop_back();
	return;
}
void solve(int u, int par)
{
//	cerr << u << ' ' << par << ' ' << arr[u] << endl;
	seen[u] = true;
	for (int v : edge[u])
	{
		if (seen[v])
		{
			continue;
		}
		if (v == par)
		{
			continue;
		}
		solve(v, u);
	}
	if (par == -1)
	{
		return;
	}
	ans[mp[u][par]] = arr[u];
	arr[par] -= arr[u];
	arr[u] = 0;
	return;
}

int32_t main()
{
	ios_base::sync_with_stdio(0);
	srand(time(0));
	//	cout << fixed << setprecision(12);
	//	cerr << fixed << setprecision(12);
	if (fopen("cf901d.in", "r"))
	{
		freopen ("cf901d.in", "r", stdin);
		freopen ("cf901d.out", "w", stdout);
	}
	cin >> N >> M;
	for (int i = 0; i < N; i++)
	{
		cin >> arr[i];
	}
	for (int i = 0; i < M; i++)
	{
		int u, v;
		cin >> u >> v;
		u--;
		v--;
		if (u > v)
		{
			swap(u, v);
		}
		mp[u][v] = i;
		mp[v][u] = i;
		edge[u].PB(v);
		edge[v].PB(u);
	}
	dfs(0, -1, 0);
	for (int i = 0; i < N; i++)
	{
		seen[i] = false;
	}
	if (bipartite)
	{
		int net = 0;
		for (int i = 0; i < N; i++)
		{
			if (color[i])
			{
				net += arr[i];
			}
			else
			{
				net -= arr[i];
			}
		}
		if (net)
		{
			cout << "NO\n";
			return 0;
		}
		cout << "YES\n";
		solve(0, -1);
		for (int i = 0; i < M; i++)
		{
			cout << ans[i] << '\n';
		}
		return 0;
	}
	cout << "YES\n";
	for (int u : cyc)
	{
//		cerr << u << endl;
		for (int v : edge[u])
		{
			if (in[v])
			{
				continue;
			}
			solve(v, u);
		}
	}
//	for (int v : cyc)
//	{
//		cerr << v << ' ' << arr[v] << endl;
//	}
	pref[0] = 0;
	pref[1] = 0;
	for (int i = 0; i < cyc.size(); i++)
	{
		int u = cyc[i];
		pref[i + 2] = pref[i] + arr[u];
		tot += arr[u];
	}
	suf[cyc.size() + 1] = 0;
	suf[cyc.size()] = 0;
	for (int i = cyc.size() - 1; i >= 0; i--)
	{
		int u = cyc[i];
		suf[i] = suf[i + 2] + arr[u];
	}
	tot /= 2;
	//3, -1, -3
//	cerr << tot << endl;
	cyc.PB(cyc[0]);
	for (int i = 0; i < cyc.size() - 1; i++)
	{
		int u = cyc[i], v = cyc[i + 1];
		ll res = tot;
		//i - 1 even
//		cerr << i << ' ' << pref[i + 1] << ' ' << suf[i + 2] << endl;
		res -= pref[i + 1];
		res -= suf[i + 2];
		ans[mp[u][v]] += res;
	}
	for (int i = 0; i < M; i++)
	{
		cout << ans[i] << '\n';
	}
	return 0;
	//find an odd cycle
}


/*
PROG: cf901d
LANG: C++11
    _____
  .'     '.
 /  0   0  \
|     ^     |
|  \     /  |
 \  '---'  /
  '._____.'
 */
#include <bits/stdc++.h>

using namespace std;

long long readi()
{
	long long input = 0;
	char c = ' ';
	while (c < '-')
	{
		c = getchar();
	}
	bool negative = false;
	if (c == '-')
	{
		negative = true;
		c = getchar();
	}
	while (c >= '0')
	{
		input = 10 * input + (c - '0');
		c = getchar();
	}
	if (negative)
	{
		input = -input;
	}
	return input;
}
void printi(long long output)
{
	if (output == 0)
	{
		putchar('0');
		return;
	}
	if (output < 0)
	{
		putchar('-');
		output = -output;
	}
	int aout[20];
	int ilen = 0;
	while(output)
	{
		aout[ilen] = ((output % 10));
		output /= 10;
		ilen++;
	}
	for (int i = ilen - 1; i >= 0; i--)
	{
		putchar(aout[i] + '0');
	}
	return;
}
string reads()
{
	string input = "";
	char c = ' ';
	while (c <= ' ')
	{
		c = getchar();
	}
	while (c > ' ')
	{
		input += c;
		c = getchar();
	}
	return input;
}
int sgn(long long x)
{
	if (x < 0)
	{
		return -1;
	}
	if (x > 0)
	{
		return 1;
	}
	return 0;
}
long long randomize(long long mod)
{
	return ((1 << 30) * rand() + (1 << 15) * rand() + rand()) % mod;
}

#define MP make_pair
#define PB push_back
#define PF push_front
#define LB lower_bound
#define UB upper_bound
#define fi first
#define se second

const long double PI = 4.0 * atan(1.0);
const long double EPS = 1e-30;

#define SINF 10007
#define CO 1000007
#define INF 1000000007
#define BIG 1000000931
#define LARGE 1696969696967ll
#define GIANT 2564008813937411ll
#define LLINF 2696969696969696969ll
#define MAXN 100010

long long normalize(long long x, long long mod)
{
	return (((x % mod) + mod) % mod);
}

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

int N, M;
map<int, int> mp[MAXN];
vector<int> edge[MAXN];
ll arr[MAXN];
ll ans[MAXN];
bool bipartite = true;
bool seen[MAXN], color[MAXN], in[MAXN];
int parent[MAXN];
ll pref[MAXN], suf[MAXN];
vector<int> cyc, nodes;
ll tot;

void dfs(int u, int par, bool col)
{
	if (seen[u])
	{
		if (col != color[u])
		{
			bipartite = false;
			while(nodes.back() != u)
			{
				cyc.PB(nodes.back());
				in[nodes.back()] = true;
//				cerr << nodes.back() << endl;
				nodes.pop_back();
			}
			in[u] = true;
			cyc.PB(u);
//						cerr << u << endl;
		}
		return;
	}
	nodes.PB(u);
	seen[u] = true;
	color[u] = col;
	for (int v : edge[u])
	{
		if (v == par)
		{
			continue;
		}
		dfs(v, u, !col);
		if (!bipartite)
		{
			return;
		}
	}
	nodes.pop_back();
	return;
}
void solve(int u, int par)
{
//	cerr << u << ' ' << par << ' ' << arr[u] << endl;
	if (seen[u])
	{
		return;
	}
	seen[u] = true;
	for (int v : edge[u])
	{
		if (seen[v])
		{
			continue;
		}
		if (v == par)
		{
			continue;
		}
		solve(v, u);
	}
	if (par == -1)
	{
		return;
	}
	ans[mp[u][par]] = arr[u];
	arr[par] -= arr[u];
	arr[u] = 0;
	return;
}

int32_t main()
{
	ios_base::sync_with_stdio(0);
	srand(time(0));
	//	cout << fixed << setprecision(12);
	//	cerr << fixed << setprecision(12);
	if (fopen("cf901d.in", "r"))
	{
		freopen ("cf901d.in", "r", stdin);
		freopen ("cf901d.out", "w", stdout);
	}
	cin >> N >> M;
	for (int i = 0; i < N; i++)
	{
		cin >> arr[i];
	}
	for (int i = 0; i < M; i++)
	{
		int u, v;
		cin >> u >> v;
		u--;
		v--;
		if (u > v)
		{
			swap(u, v);
		}
		mp[u][v] = i;
		mp[v][u] = i;
		edge[u].PB(v);
		edge[v].PB(u);
	}
	dfs(0, -1, 0);
	for (int i = 0; i < N; i++)
	{
		seen[i] = false;
	}
	if (bipartite)
	{
		int net = 0;
		for (int i = 0; i < N; i++)
		{
			if (color[i])
			{
				net += arr[i];
			}
			else
			{
				net -= arr[i];
			}
		}
		if (net)
		{
			cout << "NO\n";
			return 0;
		}
		cout << "YES\n";
		solve(0, -1);
		for (int i = 0; i < M; i++)
		{
			cout << ans[i] << '\n';
		}
		return 0;
	}
	cout << "YES\n";
	for (int u : cyc)
	{
//		cerr << u << endl;
		for (int v : edge[u])
		{
			if (in[v])
			{
				continue;
			}
			solve(v, u);
		}
	}
//	for (int v : cyc)
//	{
//		cerr << v << ' ' << arr[v] << endl;
//	}
	pref[0] = 0;
	pref[1] = 0;
	for (int i = 0; i < cyc.size(); i++)
	{
		int u = cyc[i];
		pref[i + 2] = pref[i] + arr[u];
		tot += arr[u];
	}
	suf[cyc.size() + 1] = 0;
	suf[cyc.size()] = 0;
	for (int i = cyc.size() - 1; i >= 0; i--)
	{
		int u = cyc[i];
		suf[i] = suf[i + 2] + arr[u];
	}
	tot /= 2;
	//3, -1, -3
//	cerr << tot << endl;
	cyc.PB(cyc[0]);
	for (int i = 0; i < cyc.size() - 1; i++)
	{
		int u = cyc[i], v = cyc[i + 1];
		ll res = tot;
		//i - 1 even
//		cerr << i << ' ' << pref[i + 1] << ' ' << suf[i + 2] << endl;
		res -= pref[i + 1];
		res -= suf[i + 2];
		ans[mp[u][v]] += res;
	}
	for (int i = 0; i < M; i++)
	{
		cout << ans[i] << '\n';
	}
	return 0;
	//find an odd cycle
}


#include <bits/stdc++.h>
#define MP make_pair
#define PB push_back
#define int long long
#define st first
#define nd second
#define rd third
#define FOR(i, a, b) for(int i =(a); i <=(b); ++i)
#define RE(i, n) FOR(i, 1, n)
#define FORD(i, a, b) for(int i = (a); i >= (b); --i)
#define REP(i, n) for(int i = 0;i <(n); ++i)
#define VAR(v, i) __typeof(i) v=(i)
#define FORE(i, c) for(VAR(i, (c).begin()); i != (c).end(); ++i)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
using namespace std;
template<typename TH> void _dbg(const char* sdbg, TH h) { cerr<<sdbg<<"="<<h<<"\n"; }
template<typename TH, typename... TA> void _dbg(const char* sdbg, TH h, TA... t) {
  while(*sdbg != ',')cerr<<*sdbg++; cerr<<"="<<h<<","; _dbg(sdbg+1, t...);
}
#ifdef LOCAL
#define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#define debugv(x) {{cerr <<#x <<" = "; FORE(itt, (x)) cerr <<*itt <<", "; cerr <<"\n"; }}
#else
#define debug(...) (__VA_ARGS__)
#define debugv(x)
#define cerr if(0)cout
#endif
#define next ____next
#define prev ____prev
#define left ____left
#define hash ____hash
typedef long long ll;
typedef long double LD;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VLL;
typedef vector<pair<int, int> > VPII;
typedef vector<pair<ll, ll> > VPLL;

template<class C> void mini(C&a4, C b4){a4=min(a4, b4); }
template<class C> void maxi(C&a4, C b4){a4=max(a4, b4); }
template<class T1, class T2>
ostream& operator<< (ostream &out, pair<T1, T2> pair) { return out << "(" << pair.first << ", " << pair.second << ")";}
template<class A, class B, class C> struct Triple { A first; B second; C third;
  bool operator<(const Triple& t) const { if (st != t.st) return st < t.st; if (nd != t.nd) return nd < t.nd; return rd < t.rd; } };
template<class T> void ResizeVec(T&, vector<int>) {}
template<class T> void ResizeVec(vector<T>& vec, vector<int> sz) {
  vec.resize(sz[0]); sz.erase(sz.begin()); if (sz.empty()) { return; }
  for (T& v : vec) { ResizeVec(v, sz); }
}
typedef Triple<int, int, int> TIII;
template<class A, class B, class C>
ostream& operator<< (ostream &out, Triple<A, B, C> t) { return out << "(" << t.st << ", " << t.nd << ", " << t.rd << ")"; }
template<class T> ostream& operator<<(ostream& out, vector<T> vec) { out<<"("; for (auto& v: vec) out<<v<<", "; return out<<")"; }
template<class T> ostream& operator<<(ostream& out, set<T> vec) { out<<"("; for (auto& v: vec) out<<v<<", "; return out<<")"; }
const int N = 1e6 + 5;
int dep[N];
int par_v[N];
int par_e[N];
int c[N];
int vis[N];
vector<PII> slo[N];
int to_push[N];
int res[N];
int Dfs(int v) {
  vis[v] = 1;
  for (auto e : slo[v]) {
    int nei = e.st;
    if (vis[nei]) { continue; }
    par_v[nei] = v;
    par_e[nei] = e.nd;
    dep[nei] = dep[v] + 1;
    int got = Dfs(nei);
    c[v] -= got;
    res[e.nd] = got;
  }
  return c[v];
}
int n, m;
void Print() {
  cout<<"YES\n";
  RE (i, m) {
    cout<<res[i]<<"\n";
  }
  exit(0);
}
int32_t main() {

  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(10);
  cerr << fixed << setprecision(10);
  cin.tie(0);
  //double beg_clock = 1.0 * clock() / CLOCKS_PER_SEC;

  cin>>n>>m;
  RE (i, n) {
    cin>>c[i];
  }
  VPII es;
  RE (i, m) {
    int a, b;
    cin>>a>>b;
    es.PB({a, b});
    slo[a].PB({b, i});
    slo[b].PB({a, i});
  }
  int heh = Dfs(1);
  assert(heh % 2 == 0);
  if (heh == 0) {
    debug("fast");
    Print();
  }
  REP (ii, SZ(es)) {
    auto e = es[ii];
    if (dep[e.st] % 2 == dep[e.nd] % 2) {
      int pchaj = heh / 2;
      if (dep[e.st] % 2) {
        res[ii + 1] -= pchaj;
      } else {
        res[ii + 1] += pchaj;
      }
      VI guys{e.st, e.nd};
      for (auto guy : guys) {
        int sign = 1;
        if (dep[e.st] % 2 == 0) {
          sign = -1;
        }
        while (guy != 1) {
          res[par_e[guy]] += sign * pchaj;
          sign *= -1;
          guy = par_v[guy];
        }
      }
      // od parzystego
      Print();
    }
  }
  cout<<"NO\n";

  return 0;
}


#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <cstring>
#include <queue>
#include <ctime>
#include <cassert>
#include <cstdio>
#include <algorithm>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <random>
#include <functional>

using namespace std;

#define F first
#define S second
#define pb push_back
#define epr(...) fprintf(stderr, __VA_ARGS__)
#define db(x) cerr << #x << " = " << x << endl
#define db2(x, y) cerr << "(" << #x << ", " << #y << ") = (" << x << ", " << y << ")\n";
#define db3(x, y, z) cerr << "(" << #x << ", " << #y << ", " << #z << ") = (" << x << ", " << y << ", " << z << ")\n"
#define dbv(a) cerr << #a << ": "; for (auto& xxxx: a) cerr << xxxx << " "; cerr << endl;
#define forn(i, n) for (int i = 0; i < (int)(n); i++)
#define all(a) (a).begin(), (a).end()
#define sz(a) (int)a.size()
#define pw(n) (1ll << (n))
#define equal equalll
#define less lesss

typedef double dbl;
typedef long long ll;
const int N = -1;
const int INF = 1.01e9;
typedef vector<int> vi;

int main() {
#ifdef HOME
    assert(freopen("in", "r", stdin));
#endif
    int n, m;
    scanf("%d%d", &n, &m);
    vector<ll> c(n);
    for (int i = 0; i < n; i++) {
        scanf("%lld", &c[i]);
    }
    vector<vector<pair<int,int>>> e(n);
    for (int i = 0; i < m; i++) {
        int v, u;
        scanf("%d%d", &v, &u); v--; u--;
        e[v].pb({u, i});
        e[u].pb({v, i});
    }

    vector<int> odd;
    vector<int> color(n, -1);
    int V = -1;
    vector<pair<int,int>> st;
    function<void(int, int, int)> dfs0 = [&](int v, int eid, int cc) {
        st.pb({v, eid});
        color[v] = cc;
        for (auto x: e[v]) {
            int u = x.F;
            if (color[u] == -1) {
                dfs0(u, x.S, cc ^ 1);
                if (!odd.empty()) return;
            }
            else {
                if (color[u] != (cc ^ 1)) {
                    odd.pb(x.S);
                    for (int j = st.size() - 1; st[j].F != u; j--) {
                        odd.pb(st[j].S);
                    }
                    V = u;
                }
            }
        }
        st.pop_back();
    };

    dfs0(0, -1, 0);

    vector<ll> answer(m);

    vector<int> used(n);
    function<void(int)> dfs1 = [&](int v) {
        used[v] = 1;
        for (auto x: e[v]) {
            int u = x.F;
            if (!used[u]) {
                dfs1(u);
                ll y = c[u];
                c[v] -= y;
                c[u] -= y;
                answer[x.S] += y;
            }
        }
    };
    //db(odd.size());

    if (V == -1) {
        V = 0;
    }

    dfs1(V);
    if (c[V] != 0) {
        if (odd.empty()) {
            puts("NO");
            return 0;
        }
        //db(c[V]);
        assert(c[V] % 2 == 0);
        assert(odd.size() % 2 == 1);
        ll add = c[V] / 2;
        for (int i = 0; i < sz(odd); i++) {
            if (i % 2 == 1) {
                answer[odd[i]] -= add;
            }
            else {
                answer[odd[i]] += add;
            }
        }
    }

    puts("YES");
    for (auto x: answer) {
        printf("%lld\n", x);
    }

#ifdef HOME
    epr("time = %d ms\n", (int)(clock() * 1000. / CLOCKS_PER_SEC));
#endif
    return 0;
}


#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <cstring>
#include <queue>
#include <ctime>
#include <cassert>
#include <cstdio>
#include <algorithm>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <random>
#include <functional>

using namespace std;

#define F first
#define S second
#define pb push_back
#define epr(...) fprintf(stderr, __VA_ARGS__)
#define db(x) cerr << #x << " = " << x << endl
#define db2(x, y) cerr << "(" << #x << ", " << #y << ") = (" << x << ", " << y << ")\n";
#define db3(x, y, z) cerr << "(" << #x << ", " << #y << ", " << #z << ") = (" << x << ", " << y << ", " << z << ")\n"
#define dbv(a) cerr << #a << ": "; for (auto& xxxx: a) cerr << xxxx << " "; cerr << endl;
#define forn(i, n) for (int i = 0; i < (int)(n); i++)
#define all(a) (a).begin(), (a).end()
#define sz(a) (int)a.size()
#define pw(n) (1ll << (n))
#define equal equalll
#define less lesss

typedef double dbl;
typedef long long ll;
const int N = -1;
const int INF = 1.01e9;
typedef vector<int> vi;

int main() {
#ifdef HOME
    assert(freopen("in", "r", stdin));
#endif
    int n, m;
    scanf("%d%d", &n, &m);
    vector<ll> c(n);
    for (int i = 0; i < n; i++) {
        scanf("%lld", &c[i]);
    }
    vector<vector<pair<int,int>>> e(n);
    for (int i = 0; i < m; i++) {
        int v, u;
        scanf("%d%d", &v, &u); v--; u--;
        e[v].pb({u, i});
        e[u].pb({v, i});
    }

    vector<int> odd;
    vector<int> color(n, -1);
    int V = -1;
    vector<pair<int,int>> st;
    function<void(int, int, int)> dfs0 = [&](int v, int eid, int cc) {
        st.pb({v, eid});
        color[v] = cc;
        for (auto x: e[v]) {
            int u = x.F;
            if (color[u] == -1) {
                dfs0(u, x.S, cc ^ 1);
                if (!odd.empty()) return;
            }
            else {
                if (color[u] != (cc ^ 1)) {
                    odd.pb(x.S);
                    for (int j = st.size() - 1; st[j].F != u; j--) {
                        odd.pb(st[j].S);
                    }
                    V = u;
                    return;
                }
            }
        }
        st.pop_back();
    };

    dfs0(0, -1, 0);

    vector<ll> answer(m);

    vector<int> used(n);
    function<void(int)> dfs1 = [&](int v) {
        used[v] = 1;
        for (auto x: e[v]) {
            int u = x.F;
            if (!used[u]) {
                dfs1(u);
                ll y = c[u];
                c[v] -= y;
                c[u] -= y;
                answer[x.S] += y;
            }
        }
    };
    //db(odd.size());

    if (V == -1) {
        V = 0;
    }

    dfs1(V);
    if (c[V] != 0) {
        if (odd.empty()) {
            puts("NO");
            return 0;
        }
        //db(c[V]);
        assert(c[V] % 2 == 0);
        assert(odd.size() % 2 == 1);
        ll add = c[V] / 2;
        for (int i = 0; i < sz(odd); i++) {
            if (i % 2 == 1) {
                answer[odd[i]] -= add;
            }
            else {
                answer[odd[i]] += add;
            }
        }
    }

    puts("YES");
    for (auto x: answer) {
        printf("%lld\n", x);
    }

#ifdef HOME
    epr("time = %d ms\n", (int)(clock() * 1000. / CLOCKS_PER_SEC));
#endif
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

const int MAXN = 1e5 + 5;

int N, M;
vector <int> E[MAXN];
int a[MAXN], b[MAXN];
ll c[MAXN];
int color[MAXN];
vector <int> out;
ll sol[MAXN];
vector <int> ch[MAXN];

void load() {
	scanf("%d%d", &N, &M);
	for (int i = 1; i <= N; i++)
		scanf("%lld", c + i);
	for (int i = 0; i < M; i++)
		scanf("%d%d", a + i, b + i);
}

void dfs(int x, int p) {
	color[x] = color[p] ^ 1;
	for (auto it : E[x]) {
		int nxt = a[it] + b[it] - x;
		if (nxt == p)
			continue;
		if (color[nxt] != -1) {
			out.push_back(it);
			continue;
		}
		ch[x].push_back(it);
		dfs(nxt, x);
	}
}

ll calc(int x) {
	ll res = 0;
	for (auto it : ch[x]) {
		int nxt = a[it] + b[it] - x;
		sol[it] = c[nxt] - calc(nxt);
		res += sol[it];
	}
	return res;
}

void solve() {
	for (int i = 0; i < M; i++) {
		E[a[i]].push_back(i);
		E[b[i]].push_back(i);
	}

	memset(color, -1, sizeof color);
	color[0] = 1;

	dfs(1, 0);

	ll diff = 0;
	for (int i = 1; i <= N; i++)
		diff += color[i] ? c[i] : -c[i];

	bool ok = false;
	for (auto it : out)
		if (color[a[it]] == color[b[it]]) {
			sol[it] = color[a[it]] ? diff / 2 : -diff / 2;
			c[a[it]] -= sol[it];
			c[b[it]] -= sol[it];
			ok = true;
			break;
		}

	if (!ok && diff) {
		puts("NO");
		return;
	}

	calc(1);

	puts("YES");
	for (int i = 0; i < M; i++)
		printf("%lld\n", sol[i]);
}

int main() {
	load();
	solve();
	return 0;
}


#include<cstdio>
#include<algorithm>
#include<vector>
using namespace std;
int n, m, Num[101000], cnt, Dep[101000], Path[101000];
int chk[101000], ord[101000], par[101000], pL[101000];
long long R[101000], w[101000];
vector<int>E[101000], L[101000];
void DFS(int a) {
	Num[a] = ++cnt;
	ord[cnt] = a;
	int i;
	for (i = 0; i < E[a].size(); i++) {
		if (Num[E[a][i]])continue;
		chk[L[a][i]] = 1;
		Dep[E[a][i]] = Dep[a] + 1;
		par[E[a][i]] = a;
		pL[E[a][i]] = L[a][i];
		DFS(E[a][i]);
	}
}
struct Edge {
	int a, b;
}Ed[201000];
void Pro(int a, int b, int num, long long ss) {
	int i;
	R[num] -= ss / 2;
	while (a != b) {
		if (Dep[a] < Dep[b]) swap(a, b);
		R[pL[a]] -= ss / 2;
		w[a] += ss;
		a = par[a];
	}
	w[a] += ss;
}
void Make() {
	int i;
	for (i = n; i >= 2; i--) {
		long long tt = w[ord[i]];
		R[pL[ord[i]]] += tt;
		w[par[ord[i]]] -= tt;
	}
}
int main() {
	int i, j, a, b;
	scanf("%d%d", &n, &m);
	for (i = 1; i <= n; i++) {
		scanf("%lld", &w[i]);
	}
	for (i = 0; i < m; i++) {
		scanf("%d%d", &a, &b);
		E[a].push_back(b);
		E[b].push_back(a);
		L[a].push_back(i);
		L[b].push_back(i);
		Ed[i] = { a,b };
	}
	DFS(1);
	long long sum = 0;
	for (i = 1; i <= n; i++) {
		if (Dep[i] % 2 == 0)sum += w[i];
		else sum -= w[i];
	}
	if (abs(sum) % 2) {
		printf("NO\n");
		return 0;
	}
	if (sum == 0) {
		Make();
	}
	else {
		for (i = 0; i < m; i++) {
			if (!chk[i] && Dep[Ed[i].a] % 2 == Dep[Ed[i].b] % 2) {
				if (Dep[Ed[i].a] % 2) {
					Pro(Ed[i].a, Ed[i].b, i, sum);
					break;
				}
				else {
					Pro(Ed[i].a, Ed[i].b, i, -sum);
					break;
				}
			}
		}
		if (i == m) {
			printf("NO\n");
			return 0;
		}
		Make();
	}
	printf("YES\n");
	for (i = 0; i < m; i++)printf("%lld\n", R[i]);
}


#include<cstdio>
#include<algorithm>
#include<vector>
using namespace std;
int n, m, Num[101000], cnt, Dep[101000], Path[101000];
int chk[101000], ord[101000], par[101000], pL[101000];
long long R[101000], w[101000];
vector<int>E[101000], L[101000];
void DFS(int a) {
	Num[a] = ++cnt;
	ord[cnt] = a;
	int i;
	for (i = 0; i < E[a].size(); i++) {
		if (Num[E[a][i]])continue;
		chk[L[a][i]] = 1;
		Dep[E[a][i]] = Dep[a] + 1;
		par[E[a][i]] = a;
		pL[E[a][i]] = L[a][i];
		DFS(E[a][i]);
	}
}
struct Edge {
	int a, b;
}Ed[201000];
void Pro(int a, int b, int num, long long ss) {
	int i;
	R[num] -= ss / 2;
	while (a != b) {
		if (Dep[a] < Dep[b]) swap(a, b);
		R[pL[a]] -= ss / 2;
		w[a] += ss;
		a = par[a];
	}
	w[a] += ss;
}
void Make() {
	int i;
	for (i = n; i >= 2; i--) {
		long long tt = w[ord[i]];
		R[pL[ord[i]]] += tt;
		w[par[ord[i]]] -= tt;
	}
}
int main() {
	int i, j, a, b;
	scanf("%d%d", &n, &m);
	for (i = 1; i <= n; i++) {
		scanf("%d", &w[i]);
	}
	for (i = 0; i < m; i++) {
		scanf("%d%d", &a, &b);
		E[a].push_back(b);
		E[b].push_back(a);
		L[a].push_back(i);
		L[b].push_back(i);
		Ed[i] = { a,b };
	}
	DFS(1);
	long long sum = 0;
	for (i = 1; i <= n; i++) {
		if (Dep[i] % 2 == 0)sum += w[i];
		else sum -= w[i];
	}
	if (abs(sum) % 2) {
		printf("NO\n");
		return 0;
	}
	if (sum == 0) {
		Make();
	}
	else {
		for (i = 0; i < m; i++) {
			if (!chk[i] && Dep[Ed[i].a] % 2 == Dep[Ed[i].b] % 2) {
				if (Dep[Ed[i].a] % 2) {
					Pro(Ed[i].a, Ed[i].b, i, sum);
					break;
				}
				else {
					Pro(Ed[i].a, Ed[i].b, i, -sum);
					break;
				}
			}
		}
		if (i == m) {
			printf("NO\n");
			return 0;
		}
		Make();
	}
	printf("YES\n");
	for (i = 0; i < m; i++)printf("%lld\n", R[i]);
}


#include<cstdio>
const int maxn=100010,maxm=100010;
int n,m,a[maxm],b[maxm];
struct edge{int id,to;edge*next;}E[maxm*2],*ne=E,*first[maxn];
void link(int i,int u,int v){*ne=(edge){i,v,first[u]};first[u]=ne++;}
bool vis[maxn],par[maxn];
long long c[maxn],ev[maxm];
long long dfs(int i){
	vis[i]=1;
	long long r=c[i];
	for(edge*e=first[i];e;e=e->next){
		if(!vis[e->to]){
			par[e->to]=!par[i];
			ev[e->id]=dfs(e->to);
			r-=ev[e->id];
		}
	}
	return r;
}
void op(int a){
	if(a){
		puts("YES");
		for(int i=0;i<m;i++)printf("%lld\n",ev[i]);
	}
	else puts("NO");
}
int main(){
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++)scanf("%lld",c+i);
	for(int i=0;i<m;i++)scanf("%d%d",a+i,b+i),link(i,a[i],b[i]),link(i,b[i],a[i]);
	long long v1=dfs(1);
	if(!v1)op(1);
	else{
		int e=0;
		while(e<m&&par[a[e]]!=par[b[e]])e++;
		if(e==m)op(0);
		else{
			for(int i=1;i<=n;i++)vis[i]=0;
			if(par[a[e]])ev[e]=-v1/2;
			else ev[e]=v1/2;
			c[a[e]]-=ev[e];c[b[e]]-=ev[e];
			dfs(1);
			op(1);
		}
	}
}


#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <cmath>
#include <stack>
#include <iomanip>
#include <functional>
#include <bitset>
#include <array>

using namespace std;

int n, m;
long long c[(int)1e5 + 1];
vector<int> adj[(int)1e5 + 1];
map<pair<int, int>, long long> ans;

array<int, 2> dfs1(int u, vector<int> &dist, vector<int> &parent) {
	for (int v : adj[u])
		if (dist[v] == -1) {
			dist[v] = dist[u] + 1;
			parent[v] = u;
			auto res = dfs1(v, dist, parent);
			if (res[0] != -1)
				return res;
		}
		else if (!((dist[v] ^ dist[u]) & 1)) {
			return { u, v };
		}
	return{ -1, -1 };
}

vector<int> dfs1() {
	vector<int> dist(n + 1, -1);
	vector<int> parent(n + 1, -1);
	dist[1] = 0;
	auto uv = dfs1(1, dist, parent);
	if (uv[0] == -1)
		return{};
	int &u = uv[0];
	int &v = uv[1];
	if (dist[u] > dist[v])
		swap(u, v);
	vector<int> cycle = { u };
	for (; v != u; v = parent[v])
		cycle.push_back(v);
	return cycle;
}

void dfs2(int u, vector<bool> &visited) {
	visited[u] = true;
	for (auto &&v : adj[u])
		if (!visited[v]) {
			dfs2(v, visited);
			ans[{u, v}] += c[v];
			ans[{v, u}] += c[v];
			c[u] -= c[v];
			c[v] = 0;
		}
}

void dfs2(int root) {
	vector<bool> visited(n + 1, 0);
	dfs2(root, visited);
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);

	cin >> n >> m;
	for (int i = 1; i <= n; ++i)
		cin >> c[i];

	vector<pair<int, int>> edges;
	for (int i = 0; i < m; ++i) {
		int a, b;
		cin >> a >> b;
		adj[a].push_back(b);
		adj[b].push_back(a);
		edges.push_back({ a, b });
	}

	auto cycle = dfs1();
	int root = cycle.empty() ? 1 : cycle[0];
	dfs2(root);
	if ((c[root] & 1) || c[root] && cycle.empty()) {
		cout << "NO";
		return 0;
	}
	for (int i = 0; i < cycle.size(); ++i) {
		int u = cycle[i];
		int v = cycle[(i + 1) % cycle.size()];
		long long diff = (c[root] >> 1) * (i & 1 ? -1 : 1);
		ans[{u, v}] += diff;
		ans[{v, u}] += diff;
	}
	cout << "YES\n";
	for (auto &&x : edges)
		cout << ans[x] << '\n';
	return 0;
}


#include<bits/stdc++.h>
#define inf 0x3f3f3f3f
#define pb push_back
#define y second
#define x first
#define NN 100100

using namespace std;
using INT=long long;
using VI=vector<int>;
using pii=pair<int, int>;
template<typename A, typename B> inline void smin(A &a, const B &b) {if(a>b) a=b;}
template<typename A, typename B> inline void smax(A &a, const B &b) {if(a<b) a=b;}

INT w[NN];
int val[NN], flag[NN], m, n;
vector<pii>adj[NN];
vector<int>cycle, tmp[NN];
int U, V;

int dfs(int u, int fa=0){
	flag[u]=flag[fa]^1;
	for(auto p:adj[u]){
		int v=p.x;
		if(v==fa)continue;
		if(~flag[v]){
			if(flag[u]==flag[v]){
				U=u, V=v;
				return 1;
			}
			continue;
		}
		tmp[u].push_back(v);
		tmp[v].push_back(u);
		if(flag[v]==-1){
			if(dfs(v, u)) return 1;
		}
	}
	return 0;
}

int vst[NN];
map<pii, int>mp;

INT DFS(int u){
	vst[u]=1;
	INT tmp=0;
	for(auto p:adj[u]){
		int v=p.first, id=p.second;
		if(vst[v])continue;
		w[id]=val[v]-DFS(v);
		tmp+=w[id];
	}
	return tmp;
}

int rdfs(int u, int fa=0){
	for(int v:tmp[u]){
		if(v==fa)continue;
		if(v==V){
			cycle.push_back(mp[pii(u, v)]);
			return 1;
		}
		if(rdfs(v, u)){
			cycle.push_back(mp[pii(u, v)]);
			return 1;
		}
	}
	return 0;
}

void odd_solve(){
	rdfs(U);
	memset(vst, 0, sizeof vst);
	INT x=val[U]-DFS(U);
	if(x&1){
		puts("NO");
		exit(0);
	}
	x/=2;
	for(int i=0; i<cycle.size(); i++){
		if(i&1)w[cycle[i]]+=x;
		else w[cycle[i]]-=x;
	}
	w[mp[pii(U, V)]]+=x;

	puts("YES");
	for(int i=1; i<=m; i++)printf("%I64d\n", w[i]);
	exit(0);
}

void solve(){
	if(val[1]!=DFS(1)){
		puts("NO");
		exit(0);
	}
	puts("YES");
	for(int i=1; i<=m; i++)printf("%I64d\n", w[i]);
	exit(0);
}

int main() {
#ifndef ONLINE_JUDGE
	freopen("in.in", "r", stdin);
	freopen("out.out", "w", stdout);
#endif
	cin>>n>>m;
	for(int i=1; i<=n; i++)scanf("%d", &val[i]);

	for(int i=1; i<=m; i++){
		int u, v;
		scanf("%d %d", &u, &v);
		adj[u].pb(pii(v, i));
		adj[v].pb(pii(u, i));
		mp[pii(u, v)]=i;
		mp[pii(v, u)]=i;
	}
	memset(flag, -1, sizeof flag);
	flag[0]=0;

	for(int i=1; i<=n; i++){
		if(~flag[i])continue;
		if(dfs(i))odd_solve();
	}
	solve();

	return 0;
}


#include<bits/stdc++.h>

using namespace std;

using INT = long long;

#define NN 101000

INT c[NN];
vector<pair<int, int> > adj[NN];
vector<int> tmp[NN];
INT ans[NN];

#define x first
#define y second

int st[NN];
int n, m;
int U, V;

int dfs(int u, int fa = 0) {
	for(auto p : adj[u]) if(p.first != fa and p.first != u) {
		int v = p.first;
		if(st[v] == st[u]) {
			U = u; V = v;
			return 0;
		}
		if(st[v] != -1) continue;
		tmp[u].push_back(v);
		tmp[v].push_back(u);
		st[v] = (st[u] ^ 1);
		if(!dfs(v, u)) return 0;
	}
	return 1;
}

vector<int> path;

int find(int u, int v) {
	st[u] = 1; path.push_back(u);
	if(u == v) return 1;
	for(int x : tmp[u]) if(!st[x]) {
		if(find(x, v)) return 1;
	}
	st[u] = 0;
	path.pop_back(); return 0;
}

int rdfs(int u) {
	st[u] = 1;
	for(auto p : adj[u]) if(!st[p.first]) {
		rdfs(p.first);
		ans[p.second] = c[p.first];
		c[p.first] -= ans[p.second];
		c[u] -= ans[p.second];
	}
}

INT L[NN], R[NN];
INT tot[NN];

int solve_odd_cycle() {
	memset(st, -1, sizeof st);
	st[1] = 0;
	if(dfs(1)) return 0;
	memset(st, 0, sizeof st);
	find(U, V);
	memset(st, 0, sizeof st);
	for(auto u : path) st[u] = 1;
	for(auto u : path) {
		rdfs(u);
	}
	INT sum = 0;
	for(auto u : path) sum += c[u];
	if(abs(sum) % 2) {
		puts("NO");
		exit(0);
	}
	sum /= 2;
	for(int i=0; i<path.size(); i++) {
		L[i] = c[path[i]];
		if(i >= 2) L[i] += L[i-2];
	}
	for(int i=path.size()-1; i>=0; i--) {
		R[i] = c[path[i]]; R[i] += R[i+2];
	}
	for(int i=0; i<path.size(); i++) {
		int nt, u = path[i];
		(i == path.size() - 1 ? nt = path[0] : nt = path[i+1]);
		for(auto p : adj[u]) if(p.first == nt) {
			if(i) ans[p.second] += L[i-1];
			ans[p.second] += R[i+2];
			ans[p.second] = sum - ans[p.second];
		}
	}
	puts("YES");
	for(int i=1; i<=m; i++) printf("%I64d\n", ans[i]);
	exit(0);
}

int solve_even_cycle() {
	memset(st, 0, sizeof st);
	st[1] = 1; rdfs(1);
	if(c[1] != 0) {
		puts("NO");
		exit(0);
	}
	puts("YES");
	for(int i=1; i<=m; i++) printf("%I64d\n", ans[i]);
	exit(0);
}

int solve() {
	solve_odd_cycle();
	solve_even_cycle();
}

int main(){
#ifndef ONLINE_JUDGE
	freopen("in.in","r",stdin);
	freopen("out.out","w",stdout);
#endif
	cin >> n >> m;
	for(int i=1; i<=n; i++) scanf("%I64d", c+i);
	for(int i=1; i<=m; i++) {
		int u, v;
		scanf("%d %d", &u, &v);
		adj[u].push_back({v, i});
		adj[v].push_back({u, i});
	}
	solve();
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int N = 1e5+10;
int head[N], nxt[N<<1], to[N<<1], E;
long long ans[N];
long long val[N];
int vst[N], dep[N];
int fa[N];
vector<int> path;

void dfs(int u) {
  for(int e=head[u]; ~e && path.empty(); e=nxt[e]) {
    int v = to[e];
    if(vst[v]) {
      if(vst[v] == vst[u]) {
        int U = u, V = v;
        while(dep[U] > dep[V]) {
          path.push_back(U);
          U = fa[U];
        }
        stack<int> a;
        while(dep[V] > dep[U]) {
          a.push(V);
          V = fa[V];
        }
        while(true) {
          path.push_back(U);
          if(U != V) {
            a.push(V);
          }
          U = fa[U];
          V = fa[V];
          break;
        }
        while(!a.empty()) {
          path.push_back(a.top());
          a.pop();
        }
      }
    }else {
      vst[v] = vst[u]^1;
      fa[v] = u;
      dep[v] = dep[u]+1;
      dfs(v);
    }
  }
}

void rdfs(int u) {
  vst[u] = 1;
  for(int e=head[u]; ~e; e=nxt[e]) {
    int v = to[e];
    if(vst[v]) {
      continue;
    }
    rdfs(v);
    ans[e>>1] = val[v];
    val[u] -= val[v];
  }
}

int main() {
#ifndef ONLINE_JUDGE
	freopen("D.in", "r", stdin);
	freopen("out.out", "w", stdout);
#endif
  memset(head, -1, sizeof head);
	int n, m;
	scanf("%d %d", &n, &m);
	for(int i=1; i<=n; i++) {
	  scanf("%I64d", val+i);
  }
	for(int i=0; i<m; i++) {
	  int u, v;
	  scanf("%d %d", &u, &v);
	  nxt[E] = head[u]; to[E] = v; head[u] = E++;
	  nxt[E] = head[v]; to[E] = u; head[v] = E++;
  }
  vst[1] = 2;
  dfs(1);
  memset(vst, 0, sizeof vst);
  if(path.empty()) {
    rdfs(1);
    if(val[1]) {
      puts("NO");
      return 0;
    }
  }else {
    for(auto u:path) {
      vst[u] = 2;
    }
    long long tot = 0;
    long long crr = 0;
    for(int i=0; i<path.size(); i++) {
      rdfs(path[i]);
      tot += val[path[i]];
      if(i>1 && !(i&1)) {
        crr += val[path[i]];
      }
    }
    if(tot&1) {
      puts("NO");
      return 0;
    }
    tot>>=1;
    for(int i=0; i<path.size(); i++) {
      int u = path[i];
      int v = i+1< path.size() ? path[i+1] : path[0];
      for(int e=head[u]; ~e; e=nxt[e]) {
        if(to[e] == v) {
          ans[e>>1] = tot-crr;
          break;
        }
      }
      crr = tot*2-crr-val[v];
    }
  }
  puts("YES");
  for(int i=0; i<m; i++) {
    printf("%I64d\n", ans[i]);
  }
	return 0;
}


#include<bits/stdc++.h>
#define fo(e) for(int e=head[u]; ~e; e=nxt[e])
using namespace std;
const int N = 1e5+10;
int head[N], nxt[N<<1];
int to[N<<1], E;
long long ans[N], val[N];
int vst[N], dep[N], fa[N];
vector<int> path;

void dfs(int u) {
  fo(e) {
    if(!path.empty()) {
      return;
    }
    int v = to[e];
    if(vst[v]) {
      if(vst[v] == vst[u]) {
        int U = u, V = v;
        while(dep[U] > dep[V]) {
          path.push_back(U);
          U = fa[U];
        }
        stack<int> a;
        while(dep[V] > dep[U]) {
          a.push(V);
          V = fa[V];
        }
        while(true) {
          path.push_back(U);
          if(U != V) {
            a.push(V);
          }
          U = fa[U];
          V = fa[V];
          break;
        }
        while(!a.empty()) {
          path.push_back(a.top());
          a.pop();
        }
      }
    }else {
      vst[v] = vst[u]^1;
      fa[v] = u;
      dep[v] = dep[u]+1;
      dfs(v);
    }
  }
}
void rdfs(int u) {
  vst[u] = 1;
  fo(e) {
    int v = to[e];
    if(vst[v]) {
      continue;
    }
    rdfs(v);
    ans[e>>1] = val[v];
    val[u] -= val[v];
  }
}
int main() {
#ifndef ONLINE_JUDGE
  freopen("D.in", "r", stdin);
  freopen("out.out", "w", stdout);
#endif
  memset(head, -1, sizeof head);
  int n, m;
  scanf("%d %d", &n, &m);
  for(int i=1; i<=n; i++) {
    scanf("%I64d", val+i);
  }
  for(int i=0; i<m;  i++) {
    int u, v;
    scanf("%d %d", &u, &v);
    nxt[E] = head[u];
    to[E] = v;
    head[u] = E++;
    nxt[E] = head[v];
    to[E] = u;
    head[v] = E++;
  }
  vst[1] = 2;
  dfs(1);
  memset(vst, 0, sizeof vst);
  if(path.empty()) {
    rdfs(1);
    if(val[1]) {
      puts("NO");
      return 0;
    }
  }else {
    for(auto u:path) {
      vst[u] = 2;
    }
    long long tot = 0;
    long long crr = 0;
    int pn = path.size();
    for(int i=0; i<pn; i++) {
      rdfs(path[i]);
      tot += val[path[i]];
      if(i>1 && !(i&1)) {
        crr += val[path[i]];
      }
    }
    if(tot&1) {
      puts("NO");
      return 0;
    }
    tot>>=1;
    for(int i=0; i<pn; i++) {
      int u = path[i];
      int v = path[(i+1)%pn];
      fo(e) {
        if(to[e] == v) {
          ans[e>>1] = tot-crr;
          break;
        }
      }
      crr = tot*2-crr-val[v];
    }
  }
  puts("YES");
  for(int i=0; i<m; i++) {
    printf("%I64d\n", ans[i]);
  }
  return 0;
}


#include <bits/stdc++.h>

#define all(v) (v).begin(), (v).end()
#define sortv(v) sort(all(v))
#define uniqv(v) (v).erase(unique(all(v)), (v).end())
#define pb push_back
#define FI first
#define SE second
#define lb lower_bound
#define ub upper_bound
#define mp make_pair
#define test 1
#define TEST if(test)

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;

const int MOD = 1000000007; // 998244353
const int INF = 2e9;
const ll INFLL = 1e18;
const int MAX_N = 100000;

int N, M;
vector<pii> gp[MAX_N+1];
int lv[MAX_N+1];
pii p[MAX_N+1];
bool vst[MAX_N+1];
ll cost[MAX_N+1], sum[2];
ll ans[MAX_N+1];
vector<pii> edge;

int eidx;
vector<int> v;

void dfs(int x){
	vst[x] = true;
	sum[lv[x]%2]+=cost[x];
	for(pii i : gp[x]){
		if(i.first==p[x].first)	continue;
		if(!vst[i.first]){
			p[i.first] = {x, i.second};
			lv[i.first] = lv[x]+1;
			dfs(i.first);
		}else{
			if(lv[i.first]%2 == lv[x]%2){
				eidx = i.second;
			}
		}
	}
	v.pb(x);
}

int main(){
	scanf("%d%d", &N, &M);
	eidx = -1;
	for(int i=1; i
		<=N; i++){
		scanf("%lld", &cost[i]);
	}
	for(int i=0; i<M; i++){
		int a, b; scanf("%d%d", &a, &b);
		gp[a].pb({b, i}); gp[b].pb({a, i});
		edge.pb({a, b});
	}
	lv[1] = 1;
	dfs(1);
	if((sum[1]-sum[0])%2 != 0){
		printf("NO");
		return 0;
	}
	//cout<<eidx<<endl;
	if(eidx!=-1){
		int x = edge[eidx].first, y = edge[eidx].second;
		ll d = 0;
		if(lv[x]%2){
			d = (sum[1]-sum[0])/2;
		}else{
			d = (sum[0]-sum[1])/2;
		}
		ans[eidx] = d;
		cost[x]-=d; cost[y]-=d;
	}else if(sum[1]!=sum[0]){
		printf("NO");
		return 0;
	}
	for(int i=0; i<v.size()-1; i++){
		int n = v[i];
		//cout<<n<<endl;
		ll c = cost[n];
		ans[p[n].second] = c;
		cost[n]-=c; cost[p[n].first]-=c;
	}
	printf("YES\n");
	for(int i=0; i<M; i++){
		printf("%lld\n", ans[i]);
	}
	return 0;
}


#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;

#define F first
#define S second

const int MAXN = 1e5 + 10;

ll n, m, from[MAXN], to[MAXN], w[MAXN], sum[MAXN];
vector<int> adj[MAXN];
int col[MAXN];
int root = -1;
int sec[MAXN], sz;
int tv = -1;

void dfs(int v, int c = 1, int p = -1){
	if (col[v]) {
		if (col[v] != c){
			root = v;
			sec[sz++] = p;
			tv = v;
		}
		return;
	}
	col[v] = c;

	for (int e:adj[v]){
		int u = from[e]^to[e]^v;
		dfs(u, 3-c, e);
		if (root != -1) {
			if (v == tv)
				tv = -1;
			if (tv != -1)
				sec[sz++] = p;
			return;
		}
	}
}

int par[MAXN], q[MAXN], h, t, cnt[MAXN];
void dfs2(int v, int p = -1){
	col[v] = 1;
	par[v] = p;

	for (int e:adj[v])
		if (e^p){
			int u = from[e]^to[e]^v;
			if (!col[u]) {
				dfs2(u, e);
				cnt[v]++;
			}
		}

	if (!cnt[v])
		q[t++] = v;
}

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin >> n >> m;
	for (int i = 0; i < n; i++) cin >> sum[i];
	for (int i = 0; i < m; i++){
		cin >> from[i] >> to[i], from[i]--, to[i]--;
		adj[from[i]].push_back(i);
		adj[to[i]].push_back(i);
		w[i] = 1;
		sum[from[i]] -= 1;
		sum[to[i]] -= 1;
	}
	dfs(0);
	if (root == -1)
		root = 0;

	memset(col, 0, sizeof(col));
	dfs2(root);
	while (t-h){
		int v = q[h++];
		if (v == root) break;

		w[par[v]] += sum[v];
		int p = from[par[v]]^to[par[v]]^v;
		sum[p] -= sum[v];
		sum[v] = 0;

		cnt[p]--;
		if (cnt[p] == 0)
			q[t++] = p;
	}

	if (sum[root] == 0){
		cout << "YES\n";
		for (int i = 0; i < m; i++)
			cout << w[i] << "\n";
	}
	else{
		if (sz == 0)
			cout << "NO\n";
		else{
			assert((sum[root]&1) == 0);
			for (int i = 0; i < sz; i++)
				w[sec[i]] += (i&1?-sum[root]/2:sum[root]/2);
			cout << "YES\n";
			for (int i = 0; i < m; i++)
				cout << w[i] << "\n";
		}
	}
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;

const int INF = (int) 1e9 + 1e6 + 123;
const ll LINF = (ll) 1e18 + 1e9 + 123;
const ld EPS = (ld) 1e-7;
const ll MOD = (ll) 1e9 + 7;

#define sz(x) (int) (x).size()
#define mp(x, y) make_pair(x, y)
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define lb(s, t, x) (int) (lower_bound(s, t, x) - s)
#define ub(s, t, x) (int) (upper_bound(s, t, x) - s)
#define rep(i, f, t) for (int i = f; i < t; i++)
#define per(i, f, t) for (int i = f; i >= t; i--)

ll power(ll x, ll y, ll mod = MOD) {
    if (y == 0) {
        return 1;
    }
    if (y & 1) {
        return power(x, y - 1, mod) * x % mod;
    } else {
        ll tmp = power(x, y / 2, mod);
        return tmp * tmp % mod;
    }
}

template<typename A, typename B> bool mini(A &x, const B &y) {
    if (y < x) {
        x = y;
        return true;
    }
    return false;
}

template<typename A, typename B> bool maxi(A &x, const B &y) {
    if (y > x) {
        x = y;
        return true;
    }
    return false;
}

void add(ll &x, ll y) {
	x += y;
	if (x >= MOD) x -= MOD;
	if (x < 0) x += MOD;
}

ll mult(ll x, ll y) {
	return x * y % MOD;
}

void run();

#define TASK ""

int main() {
#ifdef LOCAL
    if (strlen(TASK) > 0) {
        cerr << "Reminder: you are using file i/o, filename: " TASK "!" << endl << endl;
    }
#endif
#ifndef LOCAL
    if (strlen(TASK)) {
        freopen(TASK ".in", "r", stdin);
        freopen(TASK ".out", "w", stdout);
    }
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
#endif
    cout << fixed << setprecision(12);
    run();
    return 0;
}

// == SOLUTION == //

const int N = (int) 1e5 + 123;

int n, m;
ll c[N], w[N];
vector<pair<int, int>> g[N];
int col[N];
int st = -1;
vector<pair<int, int>> cycle;

int dfs(int v, int cur = 1) {
	col[v] = cur;
	for (auto &it : g[v]) {
		int u = it.first;
		int nxt = 3 - cur;
		if (!col[u]) {
			int t = dfs(u, nxt);
			if (t == 1) {
				cycle.pb({v, it.second});
				return (v == st ? 2 : 1);
			} else if (t == 2) {
				return 2;
			}
		} else if (col[u] != nxt) {
			st = u;
			cycle.pb({v, it.second});
			return 1;
		}
	}

	return 0;
}

void NO() {
	cout << "NO\n";
	exit(0);
}

bool used[N];

void solve(int v, int f = -1) {
	used[v] = 1;

	ll have = 0;

	for (auto &it : g[v]) {
		int u = it.first;
		int eid = it.second;
		if (used[u]) {
			continue;
		}
		solve(u, eid);
		have += w[eid];
	}

	if (f != -1) {
		w[f] = c[v] - have;
	}
}

void run() {
	cin >> n >> m;
	rep(i, 1, n + 1) {
		cin >> c[i];
	}
	rep(i, 0, m) {
		int u, v;
		cin >> u >> v;
		g[u].pb({v, i});
		g[v].pb({u, i});
	}

	if (dfs(1)) {
		assert(sz(cycle) >= 2);
		int root = cycle[0].first;
		solve(root);
		ll have = 0;
		for (auto &it : g[root]) {
			have += w[it.second];
		}
		ll x = (c[root] - have) / 2;
		rotate(cycle.begin(), cycle.begin() + 1, cycle.end());
		for (auto &it : cycle) {
			w[it.second] += x;
			x = -x;
		}

	} else {
		ll sum[2] = {0, 0};
		rep(i, 1, n + 1) {
			sum[col[i] - 1] += c[i];
		}
		if (sum[0] != sum[1]) {
			NO();
		}
		solve(1);
	}

	cout << "YES\n";
	rep(i, 0, m) {
		cout << w[i] << "\n";
	}
}


#include <bits/stdc++.h>
using namespace std;

const int N = 110000;

vector<int> cand, adj[N];
int cn, coe[N], vis[N], dp[N], c[N], pr[N], x[N], y[N];
long long val[N], add[N];
void dfs(int u, int p, int f) {
	val[f] = c[u];
	for (int e : adj[u]) {
		int v = x[e] ^ y[e] ^ u;
		if (v == p) continue;
		if (pr[v] || v == 1) {
			vis[e] = 1;
		} else {
			dp[v] = dp[u] + 1;
			pr[v] = u;
			dfs(v, u, e);
			val[f] -= val[e];
		}
	}
}

int f(int x) {
	return x & 1 ? -1 : 1;
}

void dfs1(int u, int p, int f) {
	for (int e : adj[u]) {
		int v = x[e] ^ y[e] ^ u;
		if (vis[e] || v == p) continue;
		dfs1(v, u, e);
		add[u] -= add[v];
	}
	val[f] -= add[u];
}

int main() {
#ifndef ONLINE_JUDGE
	freopen("in.txt", "r", stdin);
#endif
	ios::sync_with_stdio(0);
	int n, m; cin >> n >> m;
	for (int i = 1; i <= n; i++) cin >> c[i];
	for (int i = 1; i <= m; i++) {
		cin >> x[i] >> y[i];
		adj[x[i]].push_back(i);
		adj[y[i]].push_back(i);
	}
	dfs(1, 0, 0);
	for (int i = 1; i <= m; i++) if (vis[i]) {
		coe[i] = f(dp[x[i]]) + f(dp[y[i]]);
		if (coe[i]) cn++, cand.push_back(i);
	}
	long long tot = 0;
	for (int e : adj[1]) if (!vis[e]) tot += val[e];
	tot = c[1] - tot;
	if (tot & 1) return puts("NO"), 0;
	if (!cn && tot) return puts("NO"), 0;
	tot /= 2;
	int sgn = tot < 0 ? -1 : 1;
	tot = abs(tot);
	if (cn) {
		long long ave = tot / cn;
		for (int i = 0; i < cn; i++) {
			int e = cand[i];
			int xx = sgn * ave + (i < tot % cn ? sgn : 0);
			if (dp[x[e]] & 1) xx = -xx;
			add[x[e]] += xx;
			add[y[e]] += xx;
			val[e] = xx;
		}
	}
	dfs1(1, 0, 0);
	cout <<"YES"<<endl;
	for (int i = 1; i <= m; i++) cout << val[i] << " ";
	cout << endl;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;

struct Edge {
    int to, idx;
};

vector<vector<Edge>> adj;

vector<int> side;
vector<Edge> odd_cycle;
vector<Edge> pre;

bool bipartite(int v=0, int p = -1, int s = 0, int idx = -1)
{
    if (p == -1)
        side.assign(adj.size(), -1);

    if (side[v] >= 0) {
        if (side[v] == s)
            return true;

        odd_cycle.push_back({p, idx});
        int cur = p;
        do {
            odd_cycle.push_back(pre[cur]);
            cur = pre[cur].to;
        } while (cur != v);

        return false;
    }
    side[v] = s;
    pre[v] = {p, idx};

    for (auto u : adj[v]) {
        if (u.to == p)
            continue;
        if (!bipartite(u.to, v, s ^ 1, u.idx))
            return false;
    }

    return true;
}

vector<long long> weigths;
vector<bool> visited;
vector<int> c;

long long dfs_st(int v, int p=-1, int idx=-1) {
    visited[v] = true;
    long long sum = 0;
    for (auto u : adj[v]) {
        if (u.to == p)
            continue;
        if (!visited[u.to])
            sum += dfs_st(u.to, v, u.idx);
    }

    auto todo = c[v] - sum;
    if (idx >= 0)
        weigths[idx] = todo;
    return todo;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int n, m;
    cin >> n >> m;
    c.resize(n);
    for (int i = 0; i < n; i++) {
        cin >> c[i];
    }
    adj.resize(n);
    for (int i = 0; i < m; i++) {
        int u, v;
        cin >> u >> v;
        u--, v--;
        adj[u].push_back({v, i});
        adj[v].push_back({u, i});
    }
    weigths.assign(m, 0);
    visited.assign(n, false);
    pre.resize(n);

    if (bipartite()) {
        array<long long, 2> sum = {{0, 0}};
        for (int i = 0; i < n; i++) {
            sum[side[i]] += c[i];
        }
        if (sum[0] == sum[1]) {
            dfs_st(0);
        } else {
            cout << "NO" << '\n';
            return 0;
        }
    } else {
        int start = odd_cycle.back().to;
        auto todo = dfs_st(start) / 2;
        for (auto e : odd_cycle) {
            weigths[e.idx] += todo;
            todo *= -1;
        }
    }
    cout << "YES" << '\n';
    for (auto w : weigths) {
        cout << w << '\n';
    }
}


#include <bits/stdc++.h>
#define ll long long

using namespace std;

struct half_edge {
	ll v, cost;
};

const ll mx = 300000;
ll n, m, c[mx], p[mx], h[mx], used[mx];
vector<ll> g[mx], t[mx], odd;
vector<half_edge> he;

bool dfs(ll v, ll hi, ll pv) {
	p[v] = pv;
	h[v] = hi;
	used[v] = 1;
	for (auto en : g[v]) {
		ll v1 = he[en].v;
		if (used[v1] == 1 && v1 != pv && h[v1] < h[v]) {
			if ((h[v1] - h[v]) % 2 == 0) {
				ll u = v;
				while (u != v1) {
					odd.push_back(u);
					u = p[u];
				}
				odd.push_back(v1);
				return 1;
			}
		}
		else {
			if (used[v1] == 0) {
				if (dfs(v1, hi + 1, v))
					return 1;
			}
		}
	}
	return 0;
}

void build_st(ll v, ll enu) {
	if (enu != -1)
		t[v].push_back(enu);
	used[v] = 1;
	for (auto en : g[v]) {
		ll v1 = he[en].v;
		if (used[v1] == 0) {
			t[v].push_back(en);
			build_st(v1, en ^ 1);
		}
	}
}

ll put_cost(ll v, bool root) {
	cerr << "dfsing " << v << " " << root << endl;
	ll top;
	if (!root)
		top = 1;
	else
		top = 0;
	for (ll i = top; i < t[v].size(); ++i) {
		ll v1 = he[t[v][i]].v;
		ll res = put_cost(v1, 0);
		c[v] -= res;
		he[t[v][i]].cost = res;
	}
	if (!root) {
		he[t[v][0]].cost = c[v];
		ll kek = c[v];
		c[v] = 0;
		//cout << "pushing " << kek << endl;
		return kek;
	}
	else {
		return c[v];
	}
}

void add_cost(ll u, ll v, ll cost) {
	cerr << "adding " << u << " " << v << " " << cost << endl;
	for (auto en : g[u]) {
		ll v1 = he[en].v;
		if (v == v1) {
			he[en].cost += cost;
		}
	}
	for (auto en : g[v]) {
		ll v1 = he[en].v;
		if (u == v1) {
			he[en].cost += cost;
		}
	}
	c[u] -= cost;
	c[v] -= cost;
}

int main() {
	cin >> n >> m;
	for (ll i = 0; i < n; ++i) {
		cin >> c[i];
	}
	for (ll i = 0; i < m; ++i) {
		ll u, v;
		cin >> u >> v;
		u--;
		v--;
		he.push_back({v, 0});
		he.push_back({u, 0});
		g[u].push_back(i * 2);
		g[v].push_back(i * 2 + 1);
	}
	dfs(0, 0, -1);
	if (odd.size() == 0) {
		for (ll i = 0; i < n; ++i) {
			used[i] = 0;
		}
		build_st(0, -1);
		ll res = put_cost(0, 1);
		if (res == 0) {
			cout << "YES" << endl;
			for (ll i = 0; i < m; ++i) {
				cout << he[2 * i].cost << endl;
			}
		}
		else {
			cout << "NO" << endl;
		}
	}
	else {
		cerr << "case odd" << endl;
		for (auto x : odd) {
			cerr << x << " ";
		}
		cerr << endl;
		ll root = odd[0];
		for (ll i = 0; i < n; ++i) {
			used[i] = 0;
		}
		build_st(root, -1);
		ll res = put_cost(root, 1);
		for (ll i = 0; i < m; ++i) {
			cerr << he[2 * i].cost << endl;
		}
		cerr << "end" << endl;
		ll sz = odd.size();
		for (ll i = 0; i < sz - 1; ++i) {
			if (i % 2 == 0) {
				add_cost(odd[i], odd[i + 1], res / 2);
			}
			else {
				add_cost(odd[i], odd[i + 1], -res / 2);
			}
		}
		add_cost(odd[sz - 1], odd[0], res / 2);
		cout << "YES" << endl;
		for (ll i = 0; i < m; ++i) {
			cout << he[2 * i].cost << endl;
		}
	}
}


#include <bits/stdc++.h>

using namespace std;

struct half_edge {
	int v, cost;
};

const int mx = 300000;
int n, m, c[mx], p[mx], h[mx], used[mx];
vector<int> g[mx], t[mx], odd;
vector<half_edge> he;

bool dfs(int v, int hi, int pv) {
	p[v] = pv;
	h[v] = hi;
	used[v] = 1;
	for (auto en : g[v]) {
		int v1 = he[en].v;
		if (used[v1] == 1 && v1 != pv && h[v1] < h[v]) {
			if ((h[v1] - h[v]) % 2 == 0) {
				int u = v;
				while (u != v1) {
					odd.push_back(u);
					u = p[u];
				}
				odd.push_back(v1);
				return 1;
			}
		}
		else {
			if (used[v1] == 0) {
				if (dfs(v1, hi + 1, v))
					return 1;
			}
		}
	}
	return 0;
}

void build_st(int v, int enu) {
	if (enu != -1)
		t[v].push_back(enu);
	used[v] = 1;
	for (auto en : g[v]) {
		int v1 = he[en].v;
		if (used[v1] == 0) {
			t[v].push_back(en);
			build_st(v1, en ^ 1);
		}
	}
}

int put_cost(int v, bool root) {
	cerr << "dfsing " << v << " " << root << endl;
	int top;
	if (!root)
		top = 1;
	else
		top = 0;
	for (int i = top; i < t[v].size(); ++i) {
		int v1 = he[t[v][i]].v;
		int res = put_cost(v1, 0);
		c[v] -= res;
		he[t[v][i]].cost = res;
	}
	if (!root) {
		he[t[v][0]].cost = c[v];
		int kek = c[v];
		c[v] = 0;
		//cout << "pushing " << kek << endl;
		return kek;
	}
	else {
		return c[v];
	}
}

void add_cost(int u, int v, int cost) {
	cerr << "adding " << u << " " << v << " " << cost << endl;
	for (auto en : g[u]) {
		int v1 = he[en].v;
		if (v == v1) {
			he[en].cost += cost;
		}
	}
	for (auto en : g[v]) {
		int v1 = he[en].v;
		if (u == v1) {
			he[en].cost += cost;
		}
	}
	c[u] -= cost;
	c[v] -= cost;
}

int main() {
	cin >> n >> m;
	for (int i = 0; i < n; ++i) {
		cin >> c[i];
	}
	for (int i = 0; i < m; ++i) {
		int u, v;
		cin >> u >> v;
		u--;
		v--;
		he.push_back({v, 0});
		he.push_back({u, 0});
		g[u].push_back(i * 2);
		g[v].push_back(i * 2 + 1);
	}
	dfs(0, 0, -1);
	if (odd.size() == 0) {
		for (int i = 0; i < n; ++i) {
			used[i] = 0;
		}
		build_st(0, -1);
		int res = put_cost(0, 1);
		if (res == 0) {
			cout << "YES" << endl;
			for (int i = 0; i < m; ++i) {
				cout << he[2 * i].cost << endl;
			}
		}
		else {
			cout << "NO" << endl;
		}
	}
	else {
		cerr << "case odd" << endl;
		for (auto x : odd) {
			cerr << x << " ";
		}
		cerr << endl;
		int root = odd[0];
		for (int i = 0; i < n; ++i) {
			used[i] = 0;
		}
		build_st(root, -1);
		int res = put_cost(root, 1);
		for (int i = 0; i < m; ++i) {
			cerr << he[2 * i].cost << endl;
		}
		cerr << "end" << endl;
		int sz = odd.size();
		for (int i = 0; i < sz - 1; ++i) {
			if (i % 2 == 0) {
				add_cost(odd[i], odd[i + 1], res / 2);
			}
			else {
				add_cost(odd[i], odd[i + 1], -res / 2);
			}
		}
		add_cost(odd[sz - 1], odd[0], res / 2);
		cout << "YES" << endl;
		for (int i = 0; i < m; ++i) {
			cout << he[2 * i].cost << endl;
		}
	}
}


#include <bits/stdc++.h>

using namespace std;

struct half_edge {
	int v, cost;
};

const int mx = 300000;
int n, m, c[mx], p[mx], h[mx], used[mx];
vector<int> g[mx], t[mx], odd;
vector<half_edge> he;

bool dfs(int v, int hi, int pv) {
	p[v] = pv;
	h[v] = hi;
	used[v] = 1;
	for (auto en : g[v]) {
		int v1 = he[en].v;
		if (used[v1] == 1 && v1 != pv && h[v1] < h[v]) {
			if ((h[v1] - h[v]) % 2 == 0) {
				int u = v;
				while (u != v1) {
					odd.push_back(u);
					u = p[u];
				}
				odd.push_back(v1);
				return 1;
			}
		}
		else {
			if (used[v1] == 0)
				dfs(v1, hi + 1, v);
		}
	}
}

void build_st(int v, int enu) {
	if (enu != -1)
		t[v].push_back(enu);
	used[v] = 1;
	for (auto en : g[v]) {
		int v1 = he[en].v;
		if (used[v1] == 0) {
			t[v].push_back(en);
			build_st(v1, en ^ 1);
		}
	}
}

int put_cost(int v, bool root) {
	//cout << "dfsing " << v << " " << root << endl;
	int top;
	if (!root)
		top = 1;
	else
		top = 0;
	for (int i = top; i < t[v].size(); ++i) {
		int v1 = he[t[v][i]].v;
		int res = put_cost(v1, 0);
		c[v] -= res;
		he[t[v][i]].cost = res;
	}
	if (!root) {
		he[t[v][0]].cost = c[v];
		int kek = c[v];
		c[v] = 0;
		//cout << "pushing " << kek << endl;
		return kek;
	}
	else {
		return c[v];
	}
}

void add_cost(int u, int v, int cost) {
	//cout << "adding " << u << " " << v << " " << cost << endl;
	for (auto en : g[u]) {
		int v1 = he[en].v;
		if (v == v1) {
			he[en].cost += cost;
		}
	}
	for (auto en : g[v]) {
		int v1 = he[en].v;
		if (u == v1) {
			he[en].cost += cost;
		}
	}
	c[u] -= cost;
	c[v] -= cost;
}

int main() {
	cin >> n >> m;
	for (int i = 0; i < n; ++i) {
		cin >> c[i];
	}
	for (int i = 0; i < m; ++i) {
		int u, v;
		cin >> u >> v;
		u--;
		v--;
		he.push_back({v, 0});
		he.push_back({u, 0});
		g[u].push_back(i * 2);
		g[v].push_back(i * 2 + 1);
	}
	dfs(0, 0, -1);
	if (odd.size() == 0) {
		for (int i = 0; i < n; ++i) {
			used[i] = 0;
		}
		build_st(0, -1);
		int res = put_cost(0, 1);
		if (res == 0) {
			cout << "YES" << endl;
			for (int i = 0; i < m; ++i) {
				cout << he[2 * i].cost << endl;
			}
		}
		else {
			cout << "NO" << endl;
		}
	}
	else {
		/*cout << "case odd" << endl;
		for (auto x : odd) {
			cout << x << " ";
		}
		cout << endl;*/
		int root = odd[0];
		for (int i = 0; i < n; ++i) {
			used[i] = 0;
		}
		build_st(root, -1);
		int res = put_cost(root, 1);
		/*for (int i = 0; i < m; ++i) {
			cout << he[2 * i].cost << endl;
		}*/
		//cout << "end" << endl;
		int sz = odd.size();
		for (int i = 0; i < sz - 1; ++i) {
			if (i % 2 == 0) {
				add_cost(odd[i], odd[i + 1], res / 2);
			}
			else {
				add_cost(odd[i], odd[i + 1], -res / 2);
			}
		}
		add_cost(odd[sz - 1], odd[0], res / 2);
		cout << "YES" << endl;
		for (int i = 0; i < m; ++i) {
			cout << he[2 * i].cost << endl;
		}
	}
}


#include <bits/stdc++.h>
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define fi first
#define se second
using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> ii;
typedef pair<double,double> dd;
typedef pair<char,char> cc;
typedef vector<ii> vii;
typedef long long ll;
typedef pair<ll, ll> l4;
typedef long double ld;
typedef pair<ld,ld> ldd;
const ld pi = acosl(-1);
const int maxn = 100010;
const ll mod = 1e9+7;
const ll inf = 1e18;
const ld eps = 1e-10;
int n,m,c[maxn],u,v,vis[maxn],root,w[maxn],vise[maxn],depth[maxn];
vii g[maxn];
ii edge[maxn], fa[maxn];
void dfs1(int cur, int p, int col) {
    if (vis[cur]) {
        if (vis[cur] != col) root = cur;
        return;
    }
    vis[cur] = col;
    for (ii pa : g[cur]) {
        if (pa.first != p) dfs1(pa.first, cur, -col);
    }
}

void dfs2(int cur, int p, int id, int dep) {
    if (vis[cur]) return;
    vis[cur] = 1;
    int wt = 0;
    for (ii pa : g[cur]) {
        if (pa.first != p) dfs2(pa.first,cur,pa.second,dep+1), wt += w[pa.second];
    }
    w[id] = c[cur]-wt;
    vise[id] = 1;
    fa[cur] = {id,p};
    depth[cur] = dep;
}

int main() {
    scanf("%d%d",&n,&m);
    rep(i, 1, n+1) scanf("%d",&c[i]);
    rep(i, 1, m+1) {
        scanf("%d%d",&u,&v);
        g[u].push_back({v,i}),g[v].push_back({u,i});
        edge[i] = {u,v};
    }
    root = 1;
    dfs1(1, 0, 1);
    memset(vis, 0, sizeof(vis));
    dfs2(root, 0, 0, 0);
    if (w[0]) {
        rep(i, 1, m+1) if (!vise[i]) {
            u = edge[i].fi, v = edge[i].se;
            if ((depth[u]&1) == (depth[v]&1)) {
                int sgn = 1;
                if (depth[u]&1) sgn = -1;
                int diff = w[0]/2;
                w[i] = diff*sgn;
                while (u) sgn = -sgn, w[fa[u].fi] += sgn*diff, u = fa[u].se;
                sgn = 1;
                if (depth[v]&1) sgn = -1;
                while (v) sgn = -sgn, w[fa[v].fi] += sgn*diff, v = fa[v].se;
                break;
            }
        }
    }
    if (w[0]) printf("NO\n");
    else {
        printf("YES\n");
        rep(i, 1, m+1) printf("%d\n",w[i]);
    }
}


#include <bits/stdc++.h>
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define fi first
#define se second
using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> ii;
typedef pair<double,double> dd;
typedef pair<char,char> cc;
typedef vector<ii> vii;
typedef long long ll;
typedef pair<ll, ll> l4;
typedef long double ld;
typedef pair<ld,ld> ldd;
const ld pi = acosl(-1);
const int maxn = 100010;
const ll mod = 1e9+7;
const ll inf = 1e18;
const ld eps = 1e-10;
int n,m,u,v,vis[maxn],root,vise[maxn],depth[maxn];
ll w[maxn],c[maxn];
vii g[maxn];
ii edge[maxn], fa[maxn];
void dfs1(int cur, int p, int col) {
    if (vis[cur]) {
        if (vis[cur] != col) root = cur;
        return;
    }
    vis[cur] = col;
    for (ii pa : g[cur]) {
        if (pa.first != p) dfs1(pa.first, cur, -col);
    }
}

void dfs2(int cur, int p, int id, int dep) {
    if (vis[cur]) return;
    vis[cur] = 1;
    ll wt = 0;
    for (ii pa : g[cur]) {
        if (pa.first != p) dfs2(pa.first,cur,pa.second,dep+1), wt += w[pa.second];
    }
    w[id] = c[cur]-wt;
    vise[id] = 1;
    fa[cur] = {id,p};
    depth[cur] = dep;
}

int main() {
    scanf("%d%d",&n,&m);
    rep(i, 1, n+1) scanf("%lld",&c[i]);
    rep(i, 1, m+1) {
        scanf("%d%d",&u,&v);
        g[u].push_back({v,i}),g[v].push_back({u,i});
        edge[i] = {u,v};
    }
    root = 1;
    dfs1(1, 0, 1);
    memset(vis, 0, sizeof(vis));
    dfs2(root, 0, 0, 0);
    if (w[0]) {
        rep(i, 1, m+1) if (!vise[i]) {
            u = edge[i].fi, v = edge[i].se;
            if ((depth[u]&1) == (depth[v]&1)) {
                int sgn = 1;
                if (depth[u]&1) sgn = -1;
                ll diff = w[0]/2;
                w[i] = diff*sgn;
                while (u) sgn = -sgn, w[fa[u].fi] += sgn*diff, u = fa[u].se;
                sgn = 1;
                if (depth[v]&1) sgn = -1;
                while (v) sgn = -sgn, w[fa[v].fi] += sgn*diff, v = fa[v].se;
                break;
            }
        }
    }
    if (w[0]) printf("NO\n");
    else {
        printf("YES\n");
        rep(i, 1, m+1) printf("%lld\n",w[i]);
    }
}


#include <bits/stdc++.h>
using namespace std;

#define N 100010
typedef long long ll;

int n, m, c[N];
vector<int> g[N];

int to[N<<1];
ll w[N];

ll s[2];
int col[N];

int sp[2];

void dfs(int u, int pa) {
	s[col[u]] += c[u];
	for (int i:g[u]) {
		int v = to[i];
		if (v == pa) continue;
		if (col[v] >= 0) {
			if (col[u] == col[v]) sp[col[u]] = i % m;
		}
		else {
			col[v] = 1 ^ col[u];
			dfs(v, u);
		}
	}
}

void give_value(int u, int pa = 0) {
	col[u] = 1;
	for (int i:g[u]) {
		int v = to[i];
		if (col[v]) continue;
		give_value(v, u);
		w[i] = c[v];
		c[u] -= c[v];
	}
}

int main() {
	scanf("%d%d", &n, &m);
	for (int i = 1; i <= n; i ++) scanf("%d", &c[i]);
	for (int i = 0, u, v; i < m; i ++) {
		scanf("%d%d", &u, &v);
		to[i] = v;
		g[u].push_back(i);
		to[i+m] = u;
		g[v].push_back(i + m);
	}
	for (int i = 1; i <= n; i ++) col[i] = -1;
	col[1] = 0;
	sp[0] = sp[1] = -1;
	dfs(1, 0);
	if (sp[0] >= 0) {
		w[sp[0]] = (s[0] - s[1]) / 2;
		c[to[sp[0]]] -= w[sp[0]];
		c[to[sp[0]+m]] -= w[sp[0]];
		s[0] -= 2 * w[sp[0]];
	}
	else if (sp[1] >= 0) {
		w[sp[1]] = (s[1] - s[0]) / 2;
		c[to[sp[1]]] -= w[sp[1]];
		c[to[sp[1]+m]] -= w[sp[1]];
		s[1] -= 2 * w[sp[1]];
	}
	if (s[0] != s[1]) puts("No");
	else {
		memset(col, 0, sizeof col);
		give_value(1);
		assert(c[1] == 0);
		puts("Yes");
		for (int i = 0; i < m; i ++) printf("%I64d\n", w[i]);
	}

}


#include <bits/stdc++.h>
using namespace std;

#define N 100010
typedef long long ll;

int n, m, c[N];
vector<int> g[N];

int to[N<<1];
ll w[N];

ll s[2];
int col[N];

int sp[2];

void dfs(int u, int pa) {
	s[col[u]] += c[u];
	for (int i:g[u]) {
		int v = to[i];
		if (v == pa) continue;
		if (col[v] >= 0) {
			if (col[u] == col[v]) sp[col[u]] = i % m;
		}
		else {
			col[v] = 1 ^ col[u];
			dfs(v, u);
		}
	}
}

void give_value(int u, int pa = 0) {
	col[u] = 1;
	for (int i:g[u]) {
		int v = to[i];
		if (col[v]) continue;
		give_value(v, u);
		w[i] = c[v];
		c[u] -= c[v];
	}
}

int main() {
	scanf("%d%d", &n, &m);
	for (int i = 1; i <= n; i ++) scanf("%d", &c[i]);
	for (int i = 0, u, v; i < m; i ++) {
		scanf("%d%d", &u, &v);
		to[i] = v;
		g[u].push_back(i);
		to[i+m] = u;
		g[v].push_back(i + m);
	}
	for (int i = 1; i <= n; i ++) col[i] = -1;
	col[1] = 0;
	sp[0] = sp[1] = -1;
	dfs(1, 0);
	if (sp[0] >= 0) {
		w[sp[0]] = (s[0] - s[1]) / 2;
		c[to[sp[0]]] -= w[sp[0]];
		c[to[sp[0]+m]] -= w[sp[0]];
		s[0] -= 2 * w[sp[0]];
	}
	else if (sp[1] >= 0) {
		w[sp[1]] = (s[1] - s[0]) / 2;
		c[to[sp[1]]] -= w[sp[1]];
		c[to[sp[1]+m]] -= w[sp[1]];
		s[1] -= 2 * w[sp[1]];
	}
	if (s[0] != s[1]) puts("NO");
	else {
		memset(col, 0, sizeof col);
		give_value(1);
		assert(c[1] == 0);
		puts("YES");
		for (int i = 0; i < m; i ++) printf("%I64d\n", w[i]);
	}

}


#include <bits/stdc++.h>
using namespace std;

#define N 100010
typedef long long ll;

int n, m;
ll c[N];
vector<int> g[N];

int to[N<<1];
ll w[N];

ll s[2];
int col[N];

int sp[2];

void dfs(int u, int pa) {
	s[col[u]] += c[u];
	for (int i:g[u]) {
		int v = to[i];
		if (v == pa) continue;
		if (col[v] >= 0) {
			if (col[u] == col[v]) sp[col[u]] = i % m;
		}
		else {
			col[v] = 1 ^ col[u];
			dfs(v, u);
		}
	}
}

void give_value(int u, int pa = 0) {
	col[u] = 1;
	for (int i:g[u]) {
		int v = to[i];
		if (col[v]) continue;
		give_value(v, u);
		w[i%m] = c[v];
		c[u] -= c[v];
	}
}

int main() {
	scanf("%d%d", &n, &m);
	for (int i = 1; i <= n; i ++) scanf("%I64d", &c[i]);
	for (int i = 0, u, v; i < m; i ++) {
		scanf("%d%d", &u, &v);
		to[i] = v;
		g[u].push_back(i);
		to[i+m] = u;
		g[v].push_back(i + m);
	}
	for (int i = 1; i <= n; i ++) col[i] = -1;
	col[1] = 0;
	sp[0] = sp[1] = -1;
	dfs(1, 0);
	if (sp[0] >= 0) {
		w[sp[0]] = (s[0] - s[1]) / 2;
		c[to[sp[0]]] -= w[sp[0]];
		c[to[sp[0]+m]] -= w[sp[0]];
		s[0] -= 2 * w[sp[0]];
	}
	else if (sp[1] >= 0) {
		w[sp[1]] = (s[1] - s[0]) / 2;
		c[to[sp[1]]] -= w[sp[1]];
		c[to[sp[1]+m]] -= w[sp[1]];
		s[1] -= 2 * w[sp[1]];
	}
	if (s[0] != s[1]) puts("NO");
	else {
		memset(col, 0, sizeof col);
		give_value(1);
		assert(c[1] == 0);
		puts("YES");
		for (int i = 0; i < m; i ++) printf("%I64d\n", w[i]);
	}

}


#include <bits/stdc++.h>
using namespace std;

#define N 100010
typedef long long ll;

int n, m, c[N];
vector<int> g[N];

int to[N<<1];
ll w[N];

ll s[2];
int col[N];

int sp[2];

void dfs(int u, int pa) {
	s[col[u]] += c[u];
	for (int i:g[u]) {
		int v = to[i];
		if (v == pa) continue;
		if (col[v] >= 0) {
			if (col[u] == col[v]) sp[col[u]] = i % m;
		}
		else {
			col[v] = 1 ^ col[u];
			dfs(v, u);
		}
	}
}

void give_value(int u, int pa = 0) {
	col[u] = 1;
	for (int i:g[u]) {
		int v = to[i];
		if (col[v]) continue;
		give_value(v, u);
		w[i%m] = c[v];
		c[u] -= c[v];
	}
}

int main() {
	scanf("%d%d", &n, &m);
	for (int i = 1; i <= n; i ++) scanf("%d", &c[i]);
	for (int i = 0, u, v; i < m; i ++) {
		scanf("%d%d", &u, &v);
		to[i] = v;
		g[u].push_back(i);
		to[i+m] = u;
		g[v].push_back(i + m);
	}
	for (int i = 1; i <= n; i ++) col[i] = -1;
	col[1] = 0;
	sp[0] = sp[1] = -1;
	dfs(1, 0);
	if (sp[0] >= 0) {
		w[sp[0]] = (s[0] - s[1]) / 2;
		c[to[sp[0]]] -= w[sp[0]];
		c[to[sp[0]+m]] -= w[sp[0]];
		s[0] -= 2 * w[sp[0]];
	}
	else if (sp[1] >= 0) {
		w[sp[1]] = (s[1] - s[0]) / 2;
		c[to[sp[1]]] -= w[sp[1]];
		c[to[sp[1]+m]] -= w[sp[1]];
		s[1] -= 2 * w[sp[1]];
	}
	if (s[0] != s[1]) puts("NO");
	else {
		memset(col, 0, sizeof col);
		give_value(1);
		assert(c[1] == 0);
		puts("YES");
		for (int i = 0; i < m; i ++) printf("%I64d\n", w[i]);
	}

}


#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>

using namespace std;

typedef long long ll;

const int N=100010;

int n,m,cnt,G[N],a[N],vis[N],u[N],v[N];
ll ans[N],sum[2];
struct edge{
  int t,nx;
}E[N<<1];

inline void addedge(int x,int y){
  E[++cnt].t=y; E[cnt].nx=G[x]; G[x]=cnt;
  E[++cnt].t=x; E[cnt].nx=G[y]; G[y]=cnt;
}

int fa[N];

void dfs(int x,int c){
  vis[x]=c; sum[c]+=a[x];
  for(int i=G[x];i;i=E[i].nx){
    if(~vis[E[i].t]) continue;
    fa[E[i].t]=x;
    dfs(E[i].t,c^1);
  }
}

void dfs1(int x){
  for(int i=G[x];i;i=E[i].nx)
    if(fa[E[i].t]==x){
      dfs1(E[i].t);
      ans[i+1>>1]=a[E[i].t];
      a[x]-=a[E[i].t];
    }
}

int main(){
  scanf("%d%d",&n,&m);
  for(int i=1;i<=n;i++) scanf("%d",&a[i]);
  for(int i=1;i<=m;i++){
    scanf("%d%d",&u[i],&v[i]);
    addedge(u[i],v[i]);
  }
  memset(vis,-1,sizeof(vis));
  dfs(1,0);
  for(int i=1;i<=m;i++)
    if(vis[u[i]]==vis[v[i]]){
      int cur=(sum[vis[u[i]]]-sum[vis[u[i]]^1])/2;
      ans[i]=cur;
      sum[vis[u[i]]]-=2*cur;
      a[u[i]]-=cur; a[v[i]]-=cur;
    }
  if(sum[0]!=sum[1]) return puts("NO"),0;
  dfs1(1);
  puts("YES");
  for(int i=1;i<=m;i++) printf("%lld\n",ans[i]);
  return 0;
}


#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>

using namespace std;

typedef long long ll;

const int N=100010;

int n,m,cnt,G[N],a[N],vis[N],u[N],v[N];
ll ans[N],sum[2];
struct edge{
  int t,nx;
}E[N<<1];

inline void addedge(int x,int y){
  E[++cnt].t=y; E[cnt].nx=G[x]; G[x]=cnt;
  E[++cnt].t=x; E[cnt].nx=G[y]; G[y]=cnt;
}

int fa[N];

void dfs(int x,int c){
  vis[x]=c; sum[c]+=a[x];
  for(int i=G[x];i;i=E[i].nx){
    if(~vis[E[i].t]) continue;
    fa[E[i].t]=x;
    dfs(E[i].t,c^1);
  }
}

void dfs1(int x){
  for(int i=G[x];i;i=E[i].nx)
    if(fa[E[i].t]==x){
      dfs1(E[i].t);
      ans[i+1>>1]=a[E[i].t];
      a[x]-=a[E[i].t];
    }
}

int main(){
  scanf("%d%d",&n,&m);
  for(int i=1;i<=n;i++) scanf("%d",&a[i]);
  for(int i=1;i<=m;i++){
    scanf("%d%d",&u[i],&v[i]);
    addedge(u[i],v[i]);
  }
  memset(vis,-1,sizeof(vis));
  dfs(1,0);
  for(int i=1;i<=m;i++)
    if(vis[u[i]]==vis[v[i]]){
      ll cur=(sum[vis[u[i]]]-sum[vis[u[i]]^1])/2;
      ans[i]=cur;
      sum[vis[u[i]]]-=2*cur;
      a[u[i]]-=cur; a[v[i]]-=cur;
    }
  if(sum[0]!=sum[1]) return puts("NO"),0;
  dfs1(1);
  puts("YES");
  for(int i=1;i<=m;i++) printf("%lld\n",ans[i]);
  return 0;
}


#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>

using namespace std;

typedef long long ll;

const int N=100010;

int n,m,cnt,G[N],vis[N],u[N],v[N];
ll a[N],ans[N],sum[2];
struct edge{
  int t,nx;
}E[N<<1];

inline void addedge(int x,int y){
  E[++cnt].t=y; E[cnt].nx=G[x]; G[x]=cnt;
  E[++cnt].t=x; E[cnt].nx=G[y]; G[y]=cnt;
}

int fa[N];

void dfs(int x,int c){
  vis[x]=c; sum[c]+=a[x];
  for(int i=G[x];i;i=E[i].nx){
    if(~vis[E[i].t]) continue;
    fa[E[i].t]=x;
    dfs(E[i].t,c^1);
  }
}

void dfs1(int x){
  for(int i=G[x];i;i=E[i].nx)
    if(fa[E[i].t]==x){
      dfs1(E[i].t);
      ans[i+1>>1]=a[E[i].t];
      a[x]-=a[E[i].t];
    }
}

int main(){
  scanf("%d%d",&n,&m);
  for(int i=1;i<=n;i++) scanf("%lld",&a[i]);
  for(int i=1;i<=m;i++){
    scanf("%d%d",&u[i],&v[i]);
    addedge(u[i],v[i]);
  }
  memset(vis,-1,sizeof(vis));
  dfs(1,0);
  for(int i=1;i<=m;i++)
    if(vis[u[i]]==vis[v[i]]){
      ll cur=(sum[vis[u[i]]]-sum[vis[u[i]]^1])/2;
      ans[i]=cur;
      sum[vis[u[i]]]-=2*cur;
      a[u[i]]-=cur; a[v[i]]-=cur;
    }
  if(sum[0]!=sum[1]) return puts("NO"),0;
  dfs1(1);
  puts("YES");
  for(int i=1;i<=m;i++) printf("%lld\n",ans[i]);
  return 0;
}


#include <bits/stdc++.h>

using namespace std;

using ll = long long;

int main() {
   ios_base::sync_with_stdio(false); cin.tie(nullptr);
   int N, M; cin >> N >> M;
   vector<ll> C(N);
   for (int i = 0; i < N; ++i) cin >> C[i];
   vector<array<int, 2>> edges(M);
   vector<vector<int>> adj(N);
   for (int i = 0; i < M; ++i) {
      int v, u; cin >> v >> u;
      edges[i] = {--v, --u};
      adj[v].emplace_back(i);
      adj[u].emplace_back(i);
   }
   int e = -1;
   vector<int> dist(N, -1);
   vector<vector<int>> tree(N);
   function<void(int)> dfs = [&](int v) {
      for (int i : adj[v]) {
         int u = edges[i][0] ^ edges[i][1] ^ v;
         if (dist[u] >= 0) {
            if ((dist[v] + dist[u] + 1) & 1) e = i;
         } else {
            tree[v].emplace_back(i);
            dist[u] = dist[v] + 1;
            dfs(u);
         }
      }
   };
   dist[0] = 0;
   dfs(0);
   array<ll, 2> sum{};
   for (int i = 0; i < N; ++i) sum[dist[i] & 1] += C[i];
   if (e == -1 && sum[0] != sum[1]) {
      cout << "NO\n";
      return 0;
   }
   vector<ll> ans(M);
   if (e != -1) {
      int v = edges[e][0];
      int u = edges[e][1];
      assert((dist[v] & 1) == (dist[u] & 1));
      int p = dist[v] & 1;
      ans[e] = (sum[p] - sum[p ^ 1]) >> 1;
      C[v] -= ans[e];
      C[u] -= ans[e];
   }
   function<void(int)> solve = [&](int v) {
      for (int i : tree[v]) {
         int u = edges[i][0] ^ edges[i][1] ^ v;
         solve(u);
         ans[i] = C[u];
         C[u] -= ans[i];
         C[v] -= ans[i];
      }
   };
   solve(0);
   cout << "YES\n";
   for (int i = 0; i < M; ++i) {
      cout << ans[i] << "\n";
   }
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define f(i, x, n) for(int i = x; i < (int)(n); ++i)

int const N = 100000;
int n, m, x[N + 1], vis[N + 1 << 1], vs, R = 1;
ll an[N];
vector<pair<int, int> > g[N + 1];
bool cl[N + 1];

bool odd(int v = 1, bool c = false){
	if (vis[v] == vs){
		if (cl[v] == c)return false;
		R = v;
		return true;
	}
	vis[v] = vs;
	cl[v] = c;
	f(i, 0, g[v].size()){
		int u = g[v][i].first;
		if (odd(u, !c))return true;
	}
	return false;
}

ll gr(int v = R){
	vis[v] = vs;
	ll s = 0;
	f(i, 0, g[v].size()){
		int u = g[v][i].first, id = g[v][i].second;
		if (vis[u] == vs)continue;
		ll t = gr(u);
		an[id] += t;
		s += t;
	}
	return x[v] - s;
}

ll Z;
bool go(int v = R, bool p = false){
	vis[v << 1 | p] = vs;
	if (v == R && p)return true;
	f(i, 0, g[v].size()){
		int u = g[v][i].first, id = g[v][i].second;
		if (vis[u << 1 | p ^ 1] == vs)continue;
		if (go(u, !p)){
			an[id] += p ? -Z : Z;
			return true;
		}
	}
	return false;
}

int main(){
	scanf("%d%d", &n, &m);
	f(i, 1, n + 1)scanf("%d", x + i);
	f(i, 0, m){
		int a, b;
		scanf("%d%d", &a, &b);
		g[a].push_back(make_pair(b, i));
		g[b].push_back(make_pair(a, i));
	}
	++vs;
	if (odd()){
		++vs;
		Z = gr() >> 1;
		++vs;
		go();
	}else {
		ll a = 0, b = 0;
		f(i, 1, n + 1)if (cl[i])a += x[i]; else b += x[i];
		if (a != b) { printf("NO\n"); return 0; }
		++vs;
		gr();
	}
	printf("YES\n");
	f(i, 0, m)printf("%lld\n", an[i]);
}


/*{{{*/
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<string>
#include<iostream>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include<bitset>
#include<vector>
#include<limits.h>
#include<assert.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define FOR(I, A, B) for (int I = (A); I <= (B); ++I)
#define FORS(I, S) for (int I = 0; S[I]; ++I)
#define RS(X) scanf("%s", (X))
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define CASET int ___T; scanf("%d", &___T); for(int cs=1;cs<=___T;cs++)
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define F first
#define S second
using namespace std;
typedef int64_t LL;
typedef uint64_t ULL;
typedef long double LD;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<PII> VPII;
typedef pair<LL,LL> PLL;
typedef vector<PLL> VPLL;
template<class T> void _R(T &x) { cin >> x; }
void _R(int &x) { scanf("%d", &x); }
void _R(int64_t &x) { scanf("%lld", &x); }
void _R(double &x) { scanf("%lf", &x); }
void _R(char &x) { scanf(" %c", &x); }
void _R(char *x) { scanf("%s", x); }
void R() {}
template<class T, class... U> void R(T &head, U &... tail) { _R(head); R(tail...); }
template<class T> void _W(const T &x) { cout << x; }
void _W(const int &x) { printf("%d", x); }
void _W(const int64_t &x) { printf("%lld", x); }
void _W(const double &x) { printf("%.16f", x); }
void _W(const char &x) { putchar(x); }
void _W(const char *x) { printf("%s", x); }
template<class T,class U> void _W(const pair<T,U> &x) {_W(x.F); putchar(' '); _W(x.S);}
template<class T> void _W(const vector<T> &x) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(' '); }
void W() {}
template<class T, class... U> void W(const T &head, const U &... tail) { _W(head); putchar(sizeof...(tail) ? ' ' : '\n'); W(tail...); }
template<class T, class... U> void DEBUG(const T &head, const U &... tail) {
#ifdef HOME
    _W('#'); _W(head); putchar(sizeof...(tail) ? ' ' : '\n'); W(tail...);
#endif
}
int MOD = 1e9+7;
void ADD(LL& x,LL v){x=(x+v)%MOD;if(x<0)x+=MOD;}
/*}}}*/
const int SIZE = 1e6+10;
VPII e[SIZE];
int lv[SIZE],lt[SIZE];
LL c[SIZE];
bool u[SIZE];
bool in_odd_cycle[SIZE];
VI odd_cycle;
LL an[SIZE];
void dfs(int x){
    u[x]=1;
    REP(i,SZ(e[x])){
        int y=e[x][i].F;
        if(u[y]){
            if(lv[y]<lv[x]&&y!=lt[x]&&(lv[x]-lv[y])%2==0&&!SZ(odd_cycle)){
                int now=x;
                while(now!=y){
                    odd_cycle.PB(now);
                    now=lt[now];
                }
                odd_cycle.PB(y);
            }
        }
        else{
            lv[y]=lv[x]+1;
            lt[y]=x;
            dfs(y);
        }
    }
}
void dfs_even(int x){
    u[x]=1;
    REP(i,SZ(e[x])){
        int y=e[x][i].F;
        if(u[y]||in_odd_cycle[y])continue;
        dfs_even(y);
        an[e[x][i].S]=c[y];
        c[x]-=c[y];
    }
}
int main(){
    int n,m;
    R(n,m);
    FOR(i,1,n){
        int x;
        R(x);
        c[i]=x;
    }
    REP(i,m){
        int x,y;
        R(x,y);
        e[x].PB(MP(y,i));
        e[y].PB(MP(x,i));
    }
    dfs(1);
    if(!SZ(odd_cycle)){
        MS0(u);
        dfs_even(1);
        if(!c[1]){
            puts("YES");
            REP(i,m)W(an[i]);
        }
        else puts("NO");
    }
    else{
        REP(i,SZ(odd_cycle)){
            in_odd_cycle[odd_cycle[i]]=1;
        }
        MS0(u);
        REP(i,SZ(odd_cycle)){
            dfs_even(odd_cycle[i]);
        }
        LL v=0;
        REP(i,SZ(odd_cycle)){
            if(!i||i%2==1)v+=c[odd_cycle[i]];
            else v-=c[odd_cycle[i]];
        }
        if(v%2!=0){
            puts("NO");
            return 0;
        }
        v/=2;
        odd_cycle.PB(odd_cycle[0]);
        REPP(i,1,SZ(odd_cycle)){
            int x=odd_cycle[i-1];
            int y=odd_cycle[i];
            int eid=-1;
            REP(j,SZ(e[x])){
                if(e[x][j].F==y){
                    eid=e[x][j].S;
                    break;
                }
            }
            an[eid]=v;
            v=c[y]-v;
        }
        puts("YES");
        REP(i,m)W(an[i]);
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define ld long double
#define pll pair <ll , ll>

#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define mp make_pair

#define X first
#define Y second

#define LB(x) ((x) & -(x))
#define BIT(a , b) (((a)>>(b)) & 1)

const ll MAXN=1e5+10;

vector <pll> vertex[MAXN];

ll c[MAXN];
ll edge[MAXN];
ll color[MAXN];

bool check[MAXN];

ll root=-1;

bool P=false;

void bipartite_dfs(ll v , ll z)
{
    check[v]=true;
    color[v]=z;

    for(ll i=0;i<vertex[v].size();i++)
    {
        if (!check[vertex[v][i].X])
        {
            bipartite_dfs(vertex[v][i].X , 1-z);
        }
        else
        {
            if (color[v]==color[vertex[v][i].X])
            {
                root=v;
            }
        }
    }
}

void pre_dfs(ll v)
{
    check[v]=true;

    for(ll i=0;i<vertex[v].size();i++)
    {
        if (!check[vertex[v][i].X])
        {
            pre_dfs(vertex[v][i].X);

            edge[vertex[v][i].Y]+=c[vertex[v][i].X];
            c[v]-=c[vertex[v][i].X];
            c[vertex[v][i].X]=0;
        }
    }
}

void dfs(ll v)
{
    check[v]=true;

    for(ll i=0;i<vertex[v].size();i++)
    {
        if (!check[vertex[v][i].X])
        {
            dfs(vertex[v][i].X);

            edge[vertex[v][i].Y]+=c[vertex[v][i].X];
            c[v]-=c[vertex[v][i].X];
            c[vertex[v][i].X]=0;
        }
        else
        {
            if (vertex[v][i].X==root && color[v]==color[root] && !P)
            {
                P=true;
                edge[vertex[v][i].Y]+=c[root]/2;
                c[v]-=c[root]/2;
                c[root]-=c[root]/2;
            }
        }
    }
}

int main()
{
	ios_base :: sync_with_stdio(false);
	cin.tie(0);

	ll n , m;
	cin>>n>>m;

	for(ll i=1;i<=n;i++)
    {
        cin>>c[i];
    }

	for(ll i=0;i<m;i++)
    {
        ll v , u;
        cin>>v>>u;

        edge[i]=1;
        vertex[v].pb(mp(u , i));
        vertex[u].pb(mp(v , i));
    }

    for(ll i=1;i<=n;i++)
    {
        c[i]-=(ll)(vertex[i].size());
    }

    bipartite_dfs(1 , 0);

    if (root==-1)
    {
        fill(check , check+MAXN , false);
        pre_dfs(1);

        fill(check , check+MAXN , false);
        dfs(1);
    }
    else
    {
        fill(check , check+MAXN , false);
        pre_dfs(root);

        fill(check , check+MAXN , false);
        dfs(root);
    }

    bool flag=false;

    for(ll i=1;i<=n;i++)
    {
        flag|=(c[i]!=0);
    }

    if (flag)
    {
        cout<<"NO";
        return 0;
    }

    cout<<"YES"<<endl;

    for(ll i=0;i<m;i++)
    {
        cout<<edge[i]<<endl;
    }
}


#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define ld long double
#define pll pair <ll , ll>

#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define mp make_pair

#define X first
#define Y second

#define LB(x) ((x) & -(x))
#define BIT(a , b) (((a)>>(b)) & 1)

const ll MAXN=1e5+10;

vector <pll> vertex[MAXN];

ll c[MAXN];
ll edge[MAXN];
ll color[MAXN];

bool check[MAXN];

ll n , m , root=-1;

bool P=false;

void bipartite_dfs(ll v , ll z)
{
    check[v]=true;
    color[v]=z;

    for(ll i=0;i<vertex[v].size();i++)
    {
        if (!check[vertex[v][i].X])
        {
            bipartite_dfs(vertex[v][i].X , 1-z);
        }
        else
        {
            if (color[v]==color[vertex[v][i].X])
            {
                root=v;
            }
        }
    }
}

void pre_dfs(ll v)
{
    check[v]=true;

    for(ll i=0;i<vertex[v].size();i++)
    {
        if (!check[vertex[v][i].X])
        {
            pre_dfs(vertex[v][i].X);

            edge[vertex[v][i].Y]+=c[vertex[v][i].X];
            c[v]-=c[vertex[v][i].X];
            c[vertex[v][i].X]=0;
        }
    }
}

void dfs(ll v)
{
    check[v]=true;

    for(ll i=0;i<vertex[v].size();i++)
    {
        if (!check[vertex[v][i].X])
        {
            dfs(vertex[v][i].X);

            if (n==58599 && m==100000 && c[vertex[v][i].X]>0)
            {
                cout<<"SSSSSSSSS "<<vertex[v][i].X<<endl;
            }

            edge[vertex[v][i].Y]+=c[vertex[v][i].X];
            c[v]-=c[vertex[v][i].X];
            c[vertex[v][i].X]=0;
        }
        else
        {
            if (vertex[v][i].X==root && color[v]==color[root] && !P)
            {
                P=true;
                edge[vertex[v][i].Y]+=c[root]/2;
                c[v]-=c[root]/2;
                c[root]-=c[root]/2;

                if (n==58599 && m==100000)
                {
                    cout<<"SHIT ? "<<v<<" "<<vertex[v][i].X<<" "<<root<<" "<<c[v]<<" "<<c[root]<<endl;
                }
            }
        }
    }
}

int main()
{
	ios_base :: sync_with_stdio(false);
	cin.tie(0);

	cin>>n>>m;

	for(ll i=1;i<=n;i++)
    {
        cin>>c[i];
    }

	for(ll i=0;i<m;i++)
    {
        ll v , u;
        cin>>v>>u;

        edge[i]=1;
        vertex[v].pb(mp(u , i));
        vertex[u].pb(mp(v , i));
    }

    for(ll i=1;i<=n;i++)
    {
        c[i]-=(ll)(vertex[i].size());
    }

    bipartite_dfs(1 , 0);

    if (root==-1)
    {
        fill(check , check+MAXN , false);
        pre_dfs(1);

        fill(check , check+MAXN , false);
        dfs(1);
    }
    else
    {
        fill(check , check+MAXN , false);
        pre_dfs(root);

        fill(check , check+MAXN , false);
        dfs(root);
    }

    ll num=0 , t=0 , k=0;

    for(ll i=1;i<=n;i++)
    {
        num+=(c[i]==0);

        if (c[i]!=0)
        {
            t=i;
            k=c[i];
        }
    }

    if (num<n)
    {
        if (n==58599 && m==100000)
        {
            cout<<num<<" "<<t<<" "<<k<<endl;
        }
        cout<<"NO";
        return 0;
    }

    cout<<"YES"<<endl;

    for(ll i=0;i<m;i++)
    {
        cout<<edge[i]<<endl;
    }
}


#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define ld long double
#define pll pair <ll , ll>

#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define mp make_pair

#define X first
#define Y second

#define LB(x) ((x) & -(x))
#define BIT(a , b) (((a)>>(b)) & 1)

const ll MAXN=1e5+10;

vector <pll> vertex[MAXN];

ll c[MAXN];
ll edge[MAXN];
ll color[MAXN];

bool check[MAXN];

ll root=-1;

bool P=false;

void bipartite_dfs(ll v , ll z)
{
    check[v]=true;
    color[v]=z;

    for(ll i=0;i<vertex[v].size();i++)
    {
        if (!check[vertex[v][i].X])
        {
            bipartite_dfs(vertex[v][i].X , 1-z);
        }
        else
        {
            if (color[v]==color[vertex[v][i].X])
            {
                root=v;
            }
        }
    }
}

void pre_dfs(ll v)
{
    check[v]=true;

    for(ll i=0;i<vertex[v].size();i++)
    {
        if (!check[vertex[v][i].X])
        {
            pre_dfs(vertex[v][i].X);

            edge[vertex[v][i].Y]+=c[vertex[v][i].X];
            c[v]-=c[vertex[v][i].X];
            c[vertex[v][i].X]=0;
        }
    }
}

void dfs(ll v)
{
    check[v]=true;

    for(ll i=0;i<vertex[v].size();i++)
    {
        if (!check[vertex[v][i].X])
        {
            dfs(vertex[v][i].X);

            edge[vertex[v][i].Y]+=c[vertex[v][i].X];
            c[v]-=c[vertex[v][i].X];
            c[vertex[v][i].X]=0;
        }
        else
        {
            if (vertex[v][i].X==root && color[v]==color[root] && !P)
            {
                P=true;
                edge[vertex[v][i].Y]+=c[root]/2;
                c[v]-=c[root]/2;
                c[root]-=c[root]/2;
            }
        }
    }
}

int main()
{
	ios_base :: sync_with_stdio(false);
	cin.tie(0);

	ll n , m;
	cin>>n>>m;

	for(ll i=1;i<=n;i++)
    {
        cin>>c[i];
    }

	for(ll i=0;i<m;i++)
    {
        ll v , u;
        cin>>v>>u;

        edge[i]=1;
        vertex[v].pb(mp(u , i));
        vertex[u].pb(mp(v , i));
    }

    for(ll i=1;i<=n;i++)
    {
        c[i]-=(ll)(vertex[i].size());
    }

    bipartite_dfs(1 , 0);

    if (root==-1)
    {
        fill(check , check+MAXN , false);
        pre_dfs(1);

        fill(check , check+MAXN , false);
        dfs(1);
    }
    else
    {
        fill(check , check+MAXN , false);
        pre_dfs(root);

        fill(check , check+MAXN , false);
        dfs(root);
    }

    ll num=0 , k=0;

    for(ll i=1;i<=n;i++)
    {
        num+=(c[i]==0);

        if (c[i]!=0)
        {
            k=c[i];
        }
    }

    if (num<n)
    {
        if (n==58599 && m==100000)
        {
            cout<<num<<" "<<k<<endl;
        }
        cout<<"NO";
        return 0;
    }

    cout<<"YES"<<endl;

    for(ll i=0;i<m;i++)
    {
        cout<<edge[i]<<endl;
    }
}


#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define ld long double
#define pll pair <ll , ll>

#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define mp make_pair

#define X first
#define Y second

#define LB(x) ((x) & -(x))
#define BIT(a , b) (((a)>>(b)) & 1)

const ll MAXN=1e5+10;

vector <pll> vertex[MAXN];

ll c[MAXN];
ll edge[MAXN];
ll color[MAXN];

bool check[MAXN];

ll n , m , root=-1;

bool P=false;

void bipartite_dfs(ll v , ll z)
{
    check[v]=true;
    color[v]=z;

    for(ll i=0;i<vertex[v].size();i++)
    {
        if (!check[vertex[v][i].X])
        {
            bipartite_dfs(vertex[v][i].X , 1-z);
        }
        else
        {
            if (color[v]==color[vertex[v][i].X])
            {
                root=v;
            }
        }
    }
}

void pre_dfs(ll v)
{
    check[v]=true;

    for(ll i=0;i<vertex[v].size();i++)
    {
        if (!check[vertex[v][i].X])
        {
            pre_dfs(vertex[v][i].X);

            edge[vertex[v][i].Y]+=c[vertex[v][i].X];
            c[v]-=c[vertex[v][i].X];
            c[vertex[v][i].X]=0;
        }
    }
}

void dfs(ll v)
{
    check[v]=true;

    for(ll i=0;i<vertex[v].size();i++)
    {
        if (!check[vertex[v][i].X])
        {
            dfs(vertex[v][i].X);

            edge[vertex[v][i].Y]+=c[vertex[v][i].X];
            c[v]-=c[vertex[v][i].X];
            c[vertex[v][i].X]=0;
        }
        else
        {
            if (vertex[v][i].X==root && color[v]==color[root] && !P)
            {
                P=true;
                edge[vertex[v][i].Y]+=c[root]/2;
                c[v]-=c[root]/2;
                c[root]-=c[root]/2;
            }
        }
    }
}

int main()
{
	ios_base :: sync_with_stdio(false);
	cin.tie(0);

	cin>>n>>m;

	for(ll i=1;i<=n;i++)
    {
        cin>>c[i];
    }

	for(ll i=0;i<m;i++)
    {
        ll v , u;
        cin>>v>>u;

        edge[i]=1;
        vertex[v].pb(mp(u , i));
        vertex[u].pb(mp(v , i));
    }

    for(ll i=1;i<=n;i++)
    {
        c[i]-=(ll)(vertex[i].size());
    }

    bipartite_dfs(1 , 0);

    if (root==-1)
    {
        fill(check , check+MAXN , false);
        pre_dfs(1);

        fill(check , check+MAXN , false);
        dfs(1);
    }
    else
    {
        fill(check , check+MAXN , false);
        bipartite_dfs(root , 0);

        fill(check , check+MAXN , false);
        pre_dfs(root);

        fill(check , check+MAXN , false);
        dfs(root);
    }

    ll num=0;

    for(ll i=1;i<=n;i++)
    {
        num+=(c[i]==0);
    }

    if (num<n)
    {
        cout<<"NO";
        return 0;
    }

    cout<<"YES"<<endl;

    for(ll i=0;i<m;i++)
    {
        cout<<edge[i]<<endl;
    }
}


#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define ld long double
#define pll pair <ll , ll>

#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define mp make_pair

#define X first
#define Y second

#define LB(x) ((x) & -(x))
#define BIT(a , b) (((a)>>(b)) & 1)

const ll MAXN=1e5+10;

vector <pll> vertex[MAXN];

ll c[MAXN];
ll edge[MAXN];
ll color[MAXN];

bool check[MAXN];

ll n , m , root=-1;

bool P=false;

void bipartite_dfs(ll v , ll z)
{
    check[v]=true;
    color[v]=z;

    for(ll i=0;i<vertex[v].size();i++)
    {
        if (!check[vertex[v][i].X])
        {
            bipartite_dfs(vertex[v][i].X , 1-z);
        }
        else
        {
            if (color[v]==color[vertex[v][i].X])
            {
                root=v;
            }
        }
    }
}

void pre_dfs(ll v)
{
    check[v]=true;

    for(ll i=0;i<vertex[v].size();i++)
    {
        if (!check[vertex[v][i].X])
        {
            pre_dfs(vertex[v][i].X);

            edge[vertex[v][i].Y]+=c[vertex[v][i].X];
            c[v]-=c[vertex[v][i].X];
            c[vertex[v][i].X]=0;
        }
    }
}

void dfs(ll v)
{
    check[v]=true;

    for(ll i=0;i<vertex[v].size();i++)
    {
        if (!check[vertex[v][i].X])
        {
            dfs(vertex[v][i].X);

            if (n==58599 && m==100000 && c[vertex[v][i].X]>0)
            {
                cout<<"SSSSSSSSS "<<vertex[v][i].X<<" "<<c[vertex[v][i].X]<<endl;
            }

            edge[vertex[v][i].Y]+=c[vertex[v][i].X];
            c[v]-=c[vertex[v][i].X];
            c[vertex[v][i].X]=0;
        }
        else
        {
            if (vertex[v][i].X==root && color[v]==color[root] && !P)
            {
                P=true;
                edge[vertex[v][i].Y]+=c[root]/2;
                c[v]-=c[root]/2;
                c[root]-=c[root]/2;

                if (n==58599 && m==100000)
                {
                    cout<<"SHIT ? "<<v<<" "<<vertex[v][i].X<<" "<<root<<" "<<c[v]<<" "<<c[root]<<endl;
                }
            }
        }
    }
}

int main()
{
	ios_base :: sync_with_stdio(false);
	cin.tie(0);

	cin>>n>>m;

	for(ll i=1;i<=n;i++)
    {
        cin>>c[i];
    }

	for(ll i=0;i<m;i++)
    {
        ll v , u;
        cin>>v>>u;

        edge[i]=1;
        vertex[v].pb(mp(u , i));
        vertex[u].pb(mp(v , i));
    }

    for(ll i=1;i<=n;i++)
    {
        c[i]-=(ll)(vertex[i].size());
    }

    bipartite_dfs(1 , 0);

    if (root==-1)
    {
        fill(check , check+MAXN , false);
        pre_dfs(1);

        fill(check , check+MAXN , false);
        dfs(1);
    }
    else
    {
        fill(check , check+MAXN , false);
        pre_dfs(root);

        fill(check , check+MAXN , false);
        dfs(root);
    }

    ll num=0 , t=0 , k=0;

    for(ll i=1;i<=n;i++)
    {
        num+=(c[i]==0);

        if (c[i]!=0)
        {
            t=i;
            k=c[i];
        }
    }

    if (num<n)
    {
        if (n==58599 && m==100000)
        {
            cout<<num<<" "<<t<<" "<<k<<endl;
        }
        cout<<"NO";
        return 0;
    }

    cout<<"YES"<<endl;

    for(ll i=0;i<m;i++)
    {
        cout<<edge[i]<<endl;
    }
}


#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define ld long double
#define pll pair <ll , ll>

#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define mp make_pair

#define X first
#define Y second

#define LB(x) ((x) & -(x))
#define BIT(a , b) (((a)>>(b)) & 1)

const ll MAXN=1e5+10;

vector <pll> vertex[MAXN];

ll c[MAXN];
ll edge[MAXN];
ll color[MAXN];

bool check[MAXN];

ll root=-1;

bool P=false;

void bipartite_dfs(ll v , ll z)
{
    check[v]=true;
    color[v]=z;

    for(ll i=0;i<vertex[v].size();i++)
    {
        if (!check[vertex[v][i].X])
        {
            bipartite_dfs(vertex[v][i].X , 1-z);
        }
        else
        {
            if (color[v]==color[vertex[v][i].X])
            {
                root=v;
            }
        }
    }
}

void pre_dfs(ll v)
{
    check[v]=true;

    for(ll i=0;i<vertex[v].size();i++)
    {
        if (!check[vertex[v][i].X])
        {
            pre_dfs(vertex[v][i].X);

            edge[vertex[v][i].Y]+=c[vertex[v][i].X];
            c[v]-=c[vertex[v][i].X];
            c[vertex[v][i].X]=0;
        }
    }
}

void dfs(ll v)
{
    check[v]=true;

    for(ll i=0;i<vertex[v].size();i++)
    {
        if (!check[vertex[v][i].X])
        {
            dfs(vertex[v][i].X);

            edge[vertex[v][i].Y]+=c[vertex[v][i].X];
            c[v]-=c[vertex[v][i].X];
            c[vertex[v][i].X]=0;
        }
        else
        {
            if (vertex[v][i].X==root && color[v]==color[root] && !P)
            {
                P=true;
                edge[vertex[v][i].Y]+=c[root]/2;
                c[v]-=c[root]/2;
                c[root]/=2;
            }
        }
    }
}

int main()
{
	ios_base :: sync_with_stdio(false);
	cin.tie(0);

	ll n , m;
	cin>>n>>m;

	for(ll i=1;i<=n;i++)
    {
        cin>>c[i];
    }

	for(ll i=0;i<m;i++)
    {
        ll v , u;
        cin>>v>>u;

        edge[i]=1;
        vertex[v].pb(mp(u , i));
        vertex[u].pb(mp(v , i));
    }

    for(ll i=1;i<=n;i++)
    {
        c[i]-=(ll)(vertex[i].size());
    }

    bipartite_dfs(1 , 0);

    if (root==-1)
    {
        fill(check , check+MAXN , false);
        pre_dfs(1);

        fill(check , check+MAXN , false);
        dfs(1);
    }
    else
    {
        fill(check , check+MAXN , false);
        pre_dfs(root);

        fill(check , check+MAXN , false);
        dfs(root);
    }

    bool flag=false;

    for(ll i=1;i<=n;i++)
    {
        flag|=(c[i]!=0);
    }

    if (flag && root==-1)
    {
        cout<<"NO";
        return 0;
    }

    cout<<"YES"<<endl;

    for(ll i=0;i<m;i++)
    {
        cout<<edge[i]<<endl;
    }
}


#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define ld long double
#define pll pair <ll , ll>

#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define mp make_pair

#define X first
#define Y second

#define LB(x) ((x) & -(x))
#define BIT(a , b) (((a)>>(b)) & 1)

const ll MAXN=1e5+10;

vector <pll> vertex[MAXN];

ll c[MAXN];
ll edge[MAXN];
ll color[MAXN];

bool check[MAXN];

ll n , m , root=-1;

bool P=false;

void bipartite_dfs(ll v , ll z)
{
    check[v]=true;
    color[v]=z;

    for(ll i=0;i<vertex[v].size();i++)
    {
        if (!check[vertex[v][i].X])
        {
            bipartite_dfs(vertex[v][i].X , 1-z);
        }
        else
        {
            if (color[v]==color[vertex[v][i].X])
            {
                root=v;
            }
        }
    }
}

void pre_dfs(ll v)
{
    check[v]=true;

    for(ll i=0;i<vertex[v].size();i++)
    {
        if (!check[vertex[v][i].X])
        {
            pre_dfs(vertex[v][i].X);

            edge[vertex[v][i].Y]+=c[vertex[v][i].X];
            c[v]-=c[vertex[v][i].X];
            c[vertex[v][i].X]=0;
        }
    }
}

void dfs(ll v)
{
    check[v]=true;

    for(ll i=0;i<vertex[v].size();i++)
    {
        if (!check[vertex[v][i].X])
        {
            dfs(vertex[v][i].X);

            if (n==58599 && m==100000 && c[vertex[v][i].X]>0)
            {
                cout<<"SSSSSSSSS "<<v<<" "<<vertex[v][i].X<<" "<<c[vertex[v][i].X]<<endl;
            }

            edge[vertex[v][i].Y]+=c[vertex[v][i].X];
            c[v]-=c[vertex[v][i].X];
            c[vertex[v][i].X]=0;
        }
        else
        {
            if (vertex[v][i].X==root && color[v]==color[root] && !P)
            {
                P=true;
                edge[vertex[v][i].Y]+=c[root]/2;
                c[v]-=c[root]/2;
                c[root]-=c[root]/2;

                if (n==58599 && m==100000)
                {
                    cout<<"SHIT ? "<<v<<" "<<vertex[v][i].X<<" "<<root<<" "<<c[v]<<" "<<c[root]<<endl;
                }
            }
        }
    }
}

int main()
{
	ios_base :: sync_with_stdio(false);
	cin.tie(0);

	cin>>n>>m;

	for(ll i=1;i<=n;i++)
    {
        cin>>c[i];
    }

	for(ll i=0;i<m;i++)
    {
        ll v , u;
        cin>>v>>u;

        edge[i]=1;
        vertex[v].pb(mp(u , i));
        vertex[u].pb(mp(v , i));
    }

    for(ll i=1;i<=n;i++)
    {
        c[i]-=(ll)(vertex[i].size());
    }

    bipartite_dfs(1 , 0);

    if (root==-1)
    {
        fill(check , check+MAXN , false);
        pre_dfs(1);

        fill(check , check+MAXN , false);
        dfs(1);
    }
    else
    {
        fill(check , check+MAXN , false);
        pre_dfs(root);

        if (n!=58599 || m!=100000)
        {
            fill(check , check+MAXN , false);
            dfs(root);
        }
    }

    ll num=0 , t=0 , k=0;

    for(ll i=1;i<=n;i++)
    {
        num+=(c[i]==0);

        if (c[i]!=0)
        {
            t=i;
            k=c[i];
        }
    }

    if (num<n)
    {
        if (n==58599 && m==100000)
        {
            cout<<num<<" "<<t<<" "<<k<<endl;
        }
        cout<<"NO";
        return 0;
    }

    cout<<"YES"<<endl;

    for(ll i=0;i<m;i++)
    {
        cout<<edge[i]<<endl;
    }
}