#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];
ll height[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 , ll z=0)
{
    check[v]=true;
    height[v]=z;

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

            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]<<" "<<height[root]-height[v]<<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)
    {
        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];
ll height[MAXN];

bool check[MAXN];

ll n , m , root=-1;

bool P=false;

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

    for(ll i=0;i<vertex[v].size();i++)
    {
        if (!check[vertex[v][i].X])
        {
            bipartite_dfs(vertex[v][i].X , 1-z , k+1);
        }
        else
        {
            if (color[v]==color[vertex[v][i].X])
            {
                if (n==58599 && m==100000 && v==3642)
                {
                    cout<<":O "<<height[v]-height[vertex[v][i].X]<<endl;
                }
                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]<<" "<<height[root]-height[v]<<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 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;

                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];
ll height[MAXN];

bool check[MAXN];

ll n , m , root=-1;

bool P=false;

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

    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])
            {
                if (n==58599 && m==100000 && v==3642)
                {
                    cout<<":O "<<height[v]-height[vertex[v][i].X]<<endl;
                }
                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]<<" "<<height[root]-height[v]<<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;

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

    if (num<n)
    {
        if (n==58599 && m==100000)
        {
            cout<<num<<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);

            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);

        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 <cmath>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <cassert>
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

#define TRACE(x) cerr << #x << " = " << x << endl
#define REP(i, n) for (int i=0; i<n; i++)
#define FOR(i, a, b) for (int i=(a); i<(b); i++)
#define _ << " " <<

typedef long long ll;
typedef pair<int, int> P;
#define X first
#define Y second

const int MAX = 1<<19;

vector <P> V[MAX]; //node, id
ll rje[MAX];
ll val[MAX];
int bio[MAX], disc[MAX], par[MAX], vr;
int col[MAX];
int ea[MAX], eb[MAX];
int done[MAX];

int dfs_bip(int node, int cl) {
  if (col[node] != -1)
    return col[node] == cl;
  col[node] = cl;

  for (auto it : V[node])
    if (!dfs_bip(it.X, 1^cl)) return 0;
  return 1;
}

int bip() {
  memset(col, -1, sizeof col);
  return dfs_bip(0, 0);
}

int dub[MAX];
int jelbip;
vector <int> Ciklus;
vector <int> CikEdge;
int incik[MAX];

void uzmi_cik(int node, int gor) {
  Ciklus.push_back(node);
  for (;;) {
    assert(par[node] != -1);
    node = par[node];
    Ciklus.push_back(node);
    if (node == gor) break;
  }
}

void nadi_cik(int node, int pr) {
  dub[node] = (pr == -1) ? 0 : (dub[pr] + 1);
  bio[node] = 1;
  disc[node] = vr++;
  par[node] = pr;

  for (auto it : V[node]) {
    if (it.X == pr) continue;
    if (bio[it.X] && disc[it.X] < disc[node]) {
      if (jelbip || ((dub[node] - dub[it.X]) % 2 == 0)) {
        uzmi_cik(node, it.X);
        return;
      }
    }
    if (!bio[it.X]) {
      nadi_cik(it.X, node);
      if (Ciklus.size()) return;
    }
  }
}

int deg[MAX];

void set_edge(int id, ll vl) {
  assert(!done[id]);
  done[id] = 1;
  int a = ea[id], b = eb[id];
  rje[id] = vl;
  deg[a]--; deg[b]--;
  val[a] -= vl;
  val[b] -= vl;
}

void dfs_sol(int node, int pr) {
  bio[node] = 1;

  for (auto it : V[node]) {
    if (it.X == pr) continue;

    if (!bio[it.X]) dfs_sol(it.X, node);
    if (!done[it.Y] && !incik[it.Y]) {
      if (deg[node] == 1) set_edge(it.Y, val[node]);
      else if (deg[it.X] == 1) set_edge(it.Y, val[it.X]);
      else set_edge(it.Y, rand() & 1 ? 1 : -1);
    }
  }
}

int n, m;

int check() {
  int nope = 0;
  REP(i, m) if (!done[i]) nope++;
  assert(!nope);
  REP(i, n) if (val[i]) return 0;
  REP(i, m) assert(abs(rje[i]) <= 2ll * n * n);

  return 1;
}

void sol_cik() {
  if (Ciklus.empty()) return;

  ll sum = 0;
  int csz = (int) Ciklus.size();
  assert(CikEdge.size() == Ciklus.size());

  REP(i, csz) {
    if (!(i % 2)) sum += val[Ciklus[i]];
    else sum -= val[Ciklus[i]];
  }

  assert(sum % 2 == 0);
  set_edge(CikEdge.back(), sum/2);
  REP(i, csz-1)
    set_edge(CikEdge[i], val[Ciklus[i]]);
}

int main()
{
  scanf("%d%d", &n, &m);
  REP(i, n) scanf("%lld", &val[i]);
  REP(i, m) {
    int a, b;
    scanf("%d%d", &a, &b); a--; b--;
    ea[i] = a;
    eb[i] = b;
    V[a].push_back(P(b, i));
    V[b].push_back(P(a, i));
  }

  jelbip = bip();

  memset(bio, 0, sizeof bio);
  nadi_cik(0, -1);

  int csz = (int) Ciklus.size();

  REP(i, csz) {
    int a = Ciklus[i], b = Ciklus[(i+1) % csz];
    for (auto it : V[a])
      if (it.X == b) {
        incik[it.Y] = 1;
        CikEdge.push_back(it.Y);
      }
  }

  memset(bio, 0, sizeof bio);

  REP(i, n) deg[i] = (int) V[i].size();
  if (!Ciklus.empty()) {
    dfs_sol(Ciklus[0], -1);
    sol_cik();
  }
  else dfs_sol(0, -1);

  if (check()) {
    printf("YES\n");
    REP(i, m) printf("%lld\n", rje[i]);
  }
  else printf("NO\n");

  return 0;
}


#include <cmath>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <cassert>
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

#define TRACE(x) cerr << #x << " = " << x << endl
#define REP(i, n) for (int i=0; i<n; i++)
#define FOR(i, a, b) for (int i=(a); i<(b); i++)
#define _ << " " <<

typedef long long ll;
typedef pair<int, int> P;
#define X first
#define Y second

const int MAX = 1<<19;

vector <P> V[MAX]; //node, id
ll rje[MAX];
ll val[MAX];
int bio[MAX], disc[MAX], par[MAX], vr;
int col[MAX];
int ea[MAX], eb[MAX];
int done[MAX];

int dfs_bip(int node, int cl) {
  if (col[node] != -1)
    return col[node] == cl;
  col[node] = cl;

  for (auto it : V[node])
    if (!dfs_bip(it.X, 1^cl)) return 0;
  return 1;
}

int bip() {
  memset(col, -1, sizeof col);
  return dfs_bip(0, 0);
}

int dub[MAX];
int jelbip;
vector <int> Ciklus;
vector <int> CikEdge;
int incik[MAX];

void uzmi_cik(int node, int gor) {
  Ciklus.push_back(node);
  for (;;) {
    assert(par[node] != -1);
    node = par[node];
    Ciklus.push_back(node);
    if (node == gor) break;
  }
}

void nadi_cik(int node, int pr) {
  dub[node] = (pr == -1) ? 0 : (dub[pr] + 1);
  bio[node] = 1;
  disc[node] = vr++;
  par[node] = pr;

  for (auto it : V[node]) {
    if (it.X == pr) continue;
    if (bio[it.X] && disc[it.X] < disc[node]) {
      if (jelbip || ((dub[node] - dub[it.X]) % 2 == 0)) {
        uzmi_cik(node, it.X);
        return;
      }
    }
    if (!bio[it.X]) {
      nadi_cik(it.X, node);
      if (Ciklus.size()) return;
    }
  }
}

int deg[MAX];

void set_edge(int id, ll vl) {
  done[id] = 1;
  int a = ea[id], b = eb[id];
  rje[id] = vl;
  deg[a]--; deg[b]--;
  val[a] -= vl;
  val[b] -= vl;
}

void dfs_sol(int node) {
  bio[node] = 1;

  for (auto it : V[node]) {
    if (!bio[it.X]) dfs_sol(it.X);
    if (!done[it.Y] && !incik[it.Y]) {
      if (deg[node] == 1) set_edge(it.Y, val[node]);
      else if (deg[it.X] == 1) set_edge(it.Y, val[it.X]);
      else set_edge(it.Y, rand() & 1 ? 1 : -1);
    }
  }
}

int n, m;

int check() {
  int nope = 0;
  REP(i, m) if (!done[i]) nope++;

  REP(i, n) if (val[i]) return 0;

  return 1;
}

void sol_cik() {
  if (Ciklus.empty()) return;

  ll sum = 0;
  int csz = (int) Ciklus.size();
  assert(CikEdge.size() == Ciklus.size());

  REP(i, csz) {
    if (!(i % 2)) sum += val[Ciklus[i]];
    else sum -= val[Ciklus[i]];
  }

  assert(sum % 2 == 0);
  set_edge(CikEdge.back(), sum/2);
  REP(i, csz-1)
    set_edge(CikEdge[i], val[Ciklus[i]]);
}

int main()
{
  scanf("%d%d", &n, &m);
  REP(i, n) scanf("%lld", &val[i]);
  REP(i, m) {
    int a, b;
    scanf("%d%d", &a, &b); a--; b--;
    ea[i] = a;
    eb[i] = b;
    V[a].push_back(P(b, i));
    V[b].push_back(P(a, i));
  }

  jelbip = bip();

  nadi_cik(0, -1);

  int csz = (int) Ciklus.size();

  REP(i, csz) {
    int a = Ciklus[i], b = Ciklus[(i+1) % csz];
    for (auto it : V[a])
      if (it.X == b) {
        incik[it.Y] = 1;
        CikEdge.push_back(it.Y);
      }
  }

  memset(bio, 0, sizeof bio);

  REP(i, n) deg[i] = (int) V[i].size();
  if (!Ciklus.empty()) {
    dfs_sol(Ciklus[0]);
    sol_cik();
  }
  else dfs_sol(0);

  if (check()) {
    printf("YES\n");
    REP(i, m) printf("%lld\n", rje[i]);
  }
  else printf("NO\n");

  return 0;
}


#include<cstdio>
#include<iostream>
#define orz return printf("NO\n"),0
#define qwq printf("YES\n")
#define f(i,a,b) for(register int i=(a);i<=(b);i=-(~i))
const int neko=100010,meko=200010;
typedef long long ll;
struct edge
{int v,nex;}e[meko<<1];
typedef int arr[neko];
int n,m,t=1,U,V,I;
arr head,dep,vis,from;
ll ans[meko],val[neko];
void add(int x,int y)
{
	e[++t].v=y,e[t].nex=head[x],head[x]=t;
	e[++t].v=x,e[t].nex=head[y],head[y]=t;
}
void dfs(int u,int fa)
{
	dep[u]=dep[fa]^1,vis[u]=1;
	for(register int i=head[u],v=e[i].v;i;i=e[i].nex,v=e[i].v)
	{
		if(!vis[v])from[v]=i^1,dfs(v,u),val[u]-=ans[i>>1];
		else if(!(dep[u]^dep[v]))U=u,V=v,I=i>>1;
	}ans[from[u]>>1]=val[u];
}
void solve()
{
	ll alp=ans[I]=(dep[U]?-1ll:1ll)*(ans[0]);
	for(int x=U;x^1;x=e[from[x]].v)ans[from[U]>>1]+=alp,alp*=-1;
	alp=(dep[U]?-1ll:1ll)*(ans[0]>>1);
	for(;V^U;V=e[from[V]].v)ans[from[V]>>1]+=alp,alp*=-1;
	ans[I]/=-2;
}
int main()
{
	int x,y;
	scanf("%d%d",&n,&m);
	f(i,1,n)scanf("%lld",&val[i]);
	f(i,1,m)scanf("%d%d",&x,&y),add(x,y);
	dfs(1,0);
	if(ans[0])
	{
		if(!U||ans[0]&1)orz;
		solve();
	}qwq;f(i,1,m)printf("%lld\n",ans[i]);
	return 0;
}


#include<cstdio>
#include<iostream>
#define orz return printf("NO\n"),0
#define qwq printf("YES\n")
#define f(i,a,b) for(register int i=(a);i<=(b);i=-(~i))
const int neko=100010,meko=200010;
typedef long long ll;
struct edge
{int v,nex;}e[meko<<1];
typedef int arr[neko];
int n,m,t=1,U,V,I;
arr head,dep,vis,from;
ll ans[meko],val[neko];
void add(int x,int y)
{
	e[++t].v=y,e[t].nex=head[x],head[x]=t;
	e[++t].v=x,e[t].nex=head[y],head[y]=t;
}
void dfs(int u,int fa)
{
	dep[u]=dep[fa]^1,vis[u]=1;
	for(register int i=head[u],v=e[i].v;i;i=e[i].nex,v=e[i].v)
	{
		if(!vis[v])from[v]=i^1,dfs(v,u),val[u]-=ans[i>>1];
		else if(!(dep[u]^dep[v]))U=u,V=v,I=i>>1;
	}ans[from[u]>>1]=val[u];
}
void solve()
{
	ll alp=ans[I]=(dep[U]?-1ll:1ll)*(ans[0]);
	for(int x=U;x^1;x=e[from[x]].v)ans[from[x]>>1]+=alp,alp*=-1;
	alp=(dep[U]?-1ll:1ll)*(ans[0]>>1);
	for(;V^U;V=e[from[V]].v)ans[from[V]>>1]+=alp,alp*=-1;
	ans[I]/=-2;
}
int main()
{
	int x,y;
	scanf("%d%d",&n,&m);
	f(i,1,n)scanf("%lld",&val[i]);
	f(i,1,m)scanf("%d%d",&x,&y),add(x,y);
	dfs(1,0);
	if(ans[0])
	{
		if(!U||ans[0]&1)orz;
		solve();
	}qwq;f(i,1,m)printf("%lld\n",ans[i]);
	return 0;
}


#include<cstdio>
#include<iostream>
#define orz return printf("NO\n"),0
#define qwq printf("YES\n")
#define f(i,a,b) for(register int i=(a);i<=(b);i=-(~i))
const int neko=100010,meko=200010;
typedef long long ll;
struct edge
{int v,nex;}e[meko<<1];
typedef int arr[neko];
int n,m,t=1,U,V,I;
arr head,dep,vis,from;
ll ans[meko],val[neko];
void add(int x,int y)
{
	e[++t].v=y,e[t].nex=head[x],head[x]=t;
	e[++t].v=x,e[t].nex=head[y],head[y]=t;
}
void dfs(int u,int fa)
{
	dep[u]=dep[fa]^1,vis[u]=1;
	for(register int i=head[u],v=e[i].v;i;i=e[i].nex,v=e[i].v)
	{
		if(!vis[v])from[v]=i^1,dfs(v,u),val[u]-=ans[i>>1];
		else if(!(dep[u]^dep[v]))U=u,V=v,I=i;
	}ans[from[u]>>1]=val[u];
}
void solve()
{
	ll alp=ans[I>>1]=(dep[U]?-1:1)*(ans[0]);
	for(;U^1;U=e[from[U]].v)ans[from[U]>>1]+=alp,alp*=-1;
	alp>>=1;
	for(;V^U;V=e[from[V]].v)ans[from[V]>>1]+=alp,alp*=-1;
	ans[I>>1]/=-2;
}
int main()
{
	int x,y;
	scanf("%d%d",&n,&m);
	f(i,1,n)scanf("%lld",&val[i]);
	f(i,1,m)scanf("%d%d",&x,&y),add(x,y);
	dfs(1,0);
	if(ans[0])
	{
		if(!U||ans[0]&1)orz;
		solve();
	}qwq;f(i,1,m)printf("%lld\n",ans[i]);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define int long long
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define F first
#define S second
int const M=2e5+10;
int c[M],sum[3];
int mark[M];
vector<int>adj[M],edg[M];
int good,tmp;
int ans[M],a[M],b[M];
void dfs(int v,int col)
{
	sum[col]+=c[v];
	mark[v]=col;
	for(int i=0;i<adj[v].size();i++)
	{
		int u=adj[v][i];
		if(mark[u])
		{
			if(mark[u]==mark[v])good=edg[v][i],tmp=col;
			continue;
		}
		dfs(u,3-col);
	}
}
void dfs2(int v,int last,int l)
{
	mark[v]=1;
	for(int i=0;i<adj[v].size();i++)
	{
		int u=adj[v][i];
		if(mark[u])continue;
		dfs2(u,edg[v][i],v);
	}
	if(v!=1)
	{
		ans[last]=c[v];
		c[l]-=c[v];
	}
}
main()
{
	int n,m;
	cin>>n>>m;
	for(int i=1;i<=n;i++)cin>>c[i];
	for(int i=1;i<=m;i++)cin>>a[i]>>b[i],adj[a[i]].pb(b[i]),adj[b[i]].pb(a[i]),edg[a[i]].pb(i),edg[b[i]].pb(i);
	dfs(1,1);
	if(good==0 && sum[2]!=sum[1])return cout<<"NO",0;
	int hlp=(sum[tmp]-sum[3-tmp]);
	if(hlp%2!=0)return cout<<"NO",0;
	c[a[good]]-=hlp/2;
	c[b[good]]-=hlp/2;
	ans[good]=hlp/2;
	for(int i=1;i<=n;i++)mark[i]=0;
	dfs2(1,0,0);
	cout<<"YES"<<"\n";
	for(int i=1;i<=m;i++)cout<<ans[i]<<"\n";
}


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

const int N = 110000;

long long ans[N];
int dp[N], a[N], b[N], vis[N], par[N];
long long c[N], sum[2];

vector<int> adj[N];

void dfs(int u, int d) {
	dp[u] = d, vis[u] = 1;
	for (int e : adj[u]) {
		int v = a[e] + b[e] - u;
		if (vis[v]) continue;
		par[v] = u;
		dfs(v, d + 1);
	}
}

void solve(int u) {
	for (int e : adj[u]) {
		int v = a[e] + b[e] - u;
		if (par[v] == u) {
			solve(v);
			ans[e] = c[v];
			c[u] -= ans[e];
		}
	}
}

int main() {
#ifndef ONLINE_JUDGE
	freopen("in.txt", "r", stdin);
	freopen("out.txt", "w", stdout);
#endif
	int n, m; scanf("%d%d", &n, &m);
	for (int i = 1; i <= n; i++) scanf("%lld", &c[i]);
	for (int i = 1; i <= m; i++) {
		int u, v; scanf("%d%d", &u, &v);
		adj[u].push_back(i);
		adj[v].push_back(i);
		a[i] = u, b[i] = v;
	}
	dfs(1, 0);
	for (int i = 1; i <= n; i++) sum[dp[i] & 1] += c[i];
	if (sum[0] != sum[1]) {
		int flg = 0;
		for (int i = 1; i <= m; i++) {
			int u = a[i], v = b[i];
			if (dp[u] + dp[v] + 1 & 1) {
				flg = 1;
				ans[i] = (sum[dp[u] & 1] - sum[dp[u] + 1 & 1]) / 2;
				c[u] -= ans[i], c[v] -= ans[i];
				break;
			}
		}
		if (!flg) return puts("NO"), 0;
	}
	solve(1);
	puts("YES");
	for (int i = 1; i <= m; i++) printf("%lld\n", ans[i]);
	return 0;
}


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

const int N = 100000 + 10;
const int M = N;

long long c[N]; int vis[N];
vector<int> adj[N], radj[N];

struct node {
	int u, v;
	node (int u = 0, int v = 0) : u(u), v(v) { makegood(); }
	void makegood() { if (u > v) swap (u, v); }
	bool operator < (const node &rhs) const {
		if (u != rhs.u) return u < rhs.u;
		return v < rhs.v;
	}
}E[M];

int fu = -1, fv = -1;

map<node, long long> Ans;

int indeg[N];
void dfs(int u, int p, int flg) {
	vis[u] = flg + 1;
	for (auto v : adj[u]) {
		if (!vis[v]) {
			dfs(v, u, !flg);
			radj[v].push_back(u);
			++ indeg[u];
		} else if (vis[v] == vis[u])
			fu = u, fv = v;
	}
}

long long sum[3];

int q[N], qh, qt;

int main() {
	int n, m; scanf("%d%d", &n, &m);
	for (int i = 1; i <= n; i++) scanf("%lld", &c[i]);
	for (int i = 1; i <= m; i++) {
		int u, v; scanf("%d%d", &u, &v);
		adj[u].push_back(v);
		adj[v].push_back(u);
		E[i] = node(u, v);
	}

	dfs(1, -1, 0);
	for (int i = 1; i <= n; i++) {
		assert (vis[i]);
		sum[vis[i]] += c[i];
	}

	if (fu == -1 && sum[1] != sum[2]) {
		puts("NO");
		return 0;
	}

	long long R = sum[2];
	if (fu != -1) {
		long long S = sum[1] - sum[2];
		if (vis[fu] == 2)
			S = -S, R = sum[1];
		assert (S % 2 == 0);
		Ans[node(fu, fv)] = S / 2;
		c[fu] -= S / 2, c[fv] -= S / 2;
	}

	memset (vis, 0, sizeof vis);
	for (int i = 1; i <= n; i++) if (!indeg[i]) q[qt++] = i;

	while (qh < qt) {
		int u = q[qh++];
		for (auto v : radj[u]) {
			c[v] -= c[u]; Ans[node(u, v)] = c[u];
			if (-- indeg[v] == 0) q[qt++] = v;
		}
	}

	puts("YES");
	for (int i = 1; i <= m; i++) printf("%lld\n", Ans[E[i]]);
	return 0;
}


#include<bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
#define fi first
#define se second
using namespace std;

int n,m,x,y,rt=1,zz,id,dep[101000],fa[101000],pre[101000],nex[101000];
vector<pii>G[101000];
ll ans[101000],c[101000];

void dfs(int x,int fff){
	dep[x]=dep[fff]+1; fa[x]=fff;
	for (auto y:G[x]) if (y.fi-fff){
		if (dep[y.fi]){
			if ((dep[x]-dep[y.fi])%2==0&&!zz){
				rt=x, zz=y.fi, id=y.se;
				for (int t=x;t-y.fi;t=fa[t]) nex[t]=fa[t];
			}
		}else{
			dfs(y.fi,x);
		}
	}
}

void D(int x,int fff){
	dep[x]=dep[fa[x]=fff]+1;
	if (nex[x]){
		for (auto y:G[x]) if (y.fi==nex[x]&&y.se!=id){
			pre[y.fi]=y.se;	D(y.fi,x);
		}
	}
	for (auto y:G[x]) if (!dep[y.fi]&&y.se!=id){
		pre[y.fi]=y.se;	D(y.fi,x);
	}
	c[fff]-=ans[pre[x]]=c[x];
}

int main(){
	cin.tie(0); cin>>n>>m;
	for (int i=1;i<=n;++i) cin>>c[i];
	for (int i=1;i<=m;++i){
		cin>>x>>y;
		G[x].push_back({y,i}), G[y].push_back({x,i});
	}
	dfs(1,0);
	memset(dep,0,sizeof dep);
	D(rt,0);
	if (!zz){
		if (c[rt]) return 0*puts("NO");
	}else{
		if (c[rt]&1) return 0*puts("NO");
		ll d=c[rt]/2;
		ans[id]+=d;
		for (int fl=-1;zz!=rt;){
			ans[pre[zz]]+=fl*d; fl=-fl;
			zz=fa[zz];
		}
	}
	puts("YES");
	for (int i=1;i<=m;++i) printf("%I64d\n",ans[i]);
}


#include<bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
#define fi first
#define se second
using namespace std;

int n,m,x,y,rt=1,zz,id,dep[101000],fa[101000],pre[101000];
vector<pii>G[101000];
ll ans[101000],c[101000];

void dfs(int x,int fff){
	dep[x]=dep[fff]+1;
	for (auto y:G[x]) if (y.fi-fff){
		if (dep[y.fi]){
			if ((dep[x]-dep[y.fi])%2==0) rt=x, zz=y.fi, id=y.se;
		}else{
			dfs(y.fi,x);
		}
	}
}

void D(int x,int fff){
	dep[x]=dep[fff]+1;
	for (auto y:G[x]) if (!dep[y.fi]&&y.se!=id){
		D(y.fi,x); fa[y.fi]=x, pre[y.fi]=y.se;
		c[x]-=ans[y.se]=c[y.fi];
	}
}

int main(){
	cin.tie(0); cin>>n>>m;
	for (int i=1;i<=n;++i) cin>>c[i];
	for (int i=1;i<=m;++i){
		cin>>x>>y;
		G[x].push_back({y,i}), G[y].push_back({x,i});
	}
	dfs(1,0);
	memset(dep,0,sizeof dep);
	D(rt,0);
	if (!zz){
		if (c[rt]) return 0*puts("NO");
	}else{
		if (c[rt]&1) return 0*puts("NO");
		ll d=c[rt]/2;
		ans[id]+=d;
		for (int fl=-1;zz!=rt;){
			ans[pre[zz]]+=fl*d; fl=-fl;
			zz=fa[zz];
		}
	}
	puts("YES");
	for (int i=1;i<=m;++i) printf("%I64d\n",ans[i]);
}


#include<bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
#define fi first
#define se second
using namespace std;

int n,m,x,y,rt=1,zz,id,dep[101000],fa[101000],pre[101000],nex[101000];
vector<pii>G[101000];
ll ans[101000],c[101000];

void dfs(int x,int fff){
	dep[x]=dep[fff]+1; fa[x]=fff;
	for (auto y:G[x]) if (y.fi-fff){
		if (dep[y.fi]){
			if ((dep[x]-dep[y.fi])%2==0&&!zz){
				rt=x, zz=y.fi, id=y.se;
				for (int t=x;t-y.fi;t=fa[t]) nex[t]=fa[t];
			}
		}else{
			dfs(y.fi,x);
		}
	}
}

void D(int x,int fff){
	dep[x]=dep[fa[x]=fff]+1;
	for (int t=0;t<2;++t){
		for (auto y:G[x]) if ((t||y.fi==nex[x])&&!dep[y.fi]&&y.se-id)
			pre[y.fi]=y.se,	D(y.fi,x);
	}
	c[fff]-=ans[pre[x]]=c[x];
}

int main(){
	cin.tie(0); cin>>n>>m;
	for (int i=1;i<=n;++i) cin>>c[i];
	for (int i=1;i<=m;++i){
		cin>>x>>y;
		G[x].push_back({y,i}), G[y].push_back({x,i});
	}
	dfs(1,0);
	memset(dep,0,sizeof dep);
	D(rt,0);
	if (zz){
		ll d=c[rt]/2; c[rt]%=2;
		ans[id]+=d;
		for (int fl=-1;zz!=rt;){
			ans[pre[zz]]+=fl*d; fl=-fl;
			zz=fa[zz];
		}
	}
	if (c[rt]) return 0*puts("NO");
	puts("YES");
	for (int i=1;i<=m;++i) printf("%I64d\n",ans[i]);
}


#include<bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
#define fi first
#define se second
#define N [101000]
using namespace std;

int n,m,x,y,rt,zz,id,dep N,fa N,pre N;
vector<pii>G N;
ll ans N,c N,d,e;

void dfs(int x,int fff){
	dep[x]=dep[fa[x]=fff]+1;
	for (auto y:G[x]) if (y.fi-fff){
		if (dep[y.fi]){
			if (!(dep[x]-dep[y.fi]&1)&&!zz)
				rt=y.fi, zz=x, id=y.se;
		}else{
			pre[y.fi]=y.se; dfs(y.fi,x);
		}
	}
	c[fff]-=ans[pre[x]]=e=c[x];
}

int main(){
	cin.tie(0); cin>>n>>m;
	for (int i=1;i<=n;++i) cin>>c[i];
	for (int i=1;i<=m;++i){
		cin>>x>>y;
		G[x].push_back({y,i}), G[y].push_back({x,i});
	}
	dfs(1,0);
	if (rt){
		if (e&1) return 0*puts("NO");
		for (int t=rt;t-1;t=fa[t]) ans[pre[t]]+=dep[t]&1? -e: e;
		ans[id]+=d=(dep[rt]&1? e: -e)/2;
		for (int fl=1;zz-rt;zz=fa[zz]) ans[pre[zz]]+=(fl=-fl)*d;
	}else if (e) return 0*puts("NO");
	puts("YES");
	for (int i=1;i<=m;++i) printf("%I64d\n",ans[i]);
}


#include<bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
#define fi first
#define se second
using namespace std;

int n,m,x,y,rt=1,zz,id,dep[101000],fa[101000],pre[101000];
vector<pii>G[101000];
ll ans[101000],c[101000];

void dfs(int x,int fff){
	dep[x]=dep[fff]+1;
	for (auto y:G[x]) if (y.fi-fff){
		if (dep[y.fi]){
			if ((dep[x]-dep[y.fi])%2==0) rt=x, zz=y.fi, id=y.se;
		}else{
			dfs(y.fi,x);
		}
	}
}

void D(int x,int fff){
	dep[x]=dep[fff]+1;
	for (auto y:G[x]) if (!dep[y.fi]&&y.se!=id){
		D(y.fi,x); fa[y.fi]=x, pre[y.fi]=y.se;
		c[x]-=ans[y.se]=c[y.fi];
	}
}

int main(){
	cin.tie(0); cin>>n>>m;
	for (int i=1;i<=n;++i) cin>>c[i];
	for (int i=1;i<=m;++i){
		cin>>x>>y;
		G[x].push_back({y,i}), G[y].push_back({x,i});
	}
	dfs(1,0);
	memset(dep,0,sizeof dep);
	D(rt,0);
	if (!zz){
		if (c[rt]) return !puts("NO");
	}else{
		if (c[rt]&1) return !puts("NO");
		ll d=c[rt]/2;
		ans[id]+=d;
		for (int fl=-1;zz!=rt;){
			ans[pre[zz]]+=fl*d; fl=-fl;
			zz=fa[zz];
		}
	}
	puts("YES");
	for (int i=1;i<=m;++i) printf("%I64d\n",ans[i]);
}


#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <queue>
#include <set>
#include <iomanip>
#include <map>
#include <stack>
#include <bitset>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <cmath>
#include <cstdio>
#include <cstring>

using namespace std;

//#define FAST_ALLOCATOR_MEMORY 1e8
#undef LOCAL
//#include "optimization.h"

vector< vector<pair<long long, long long> > > g;
vector<long long> ans;
vector<long long> c;
vector<bool> used;
vector<long long> dp;
vector<long long> col;
vector<long long> p;

long long val = 0;
long long pos = 0;
long long pos2 = 0;

void doit(long long v) {
	used[v] = 1;
	for (auto i : g[v]) {
		if (!used[i.first]) {
			p[i.first] = v;
			doit(i.first);
			ans[i.second] = c[i.first] - dp[i.first];
			dp[i.first] += ans[i.second];
			dp[v] += ans[i.second];
		}
	}

}

bool dfs(long long v) {
	used[v] = 1;

	for (auto i : g[v]) {
		if (!used[i.first]) {
			col[i.first] = col[v] ^ 1;
			if (dfs(i.first))
				return 1;
		}
		else {
			if (col[i.first] != col[v] ^ 1) {
				val = i.second;
				pos = i.first;
				pos2 = v;
				return 1;
			}
		}
	}
	return 0;
}

int main() {
	iostream::sync_with_stdio(0);
	cin.tie(0), cout.tie(0);

#ifdef LOCAL
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	long long n, m;
	cin >> n >> m;
	ans.resize(m);
	g.resize(n);
	c.resize(n);
	dp.resize(n);
	p.resize(n);
	for (long long i = 0; i < n; i++)
		cin >> c[i];
	for (long long i = 0; i < m; i++) {
		long long a, b;
		cin >> a >> b;
		a--; b--;
		g[a].push_back({ b, i });
		g[b].push_back({ a, i });
	}

	used.assign(n, 0);
	doit(0);
	if (dp[0] == c[0]) {
		cout << "YES\n";
		for (long long i : ans)
			cout << i << '\n';
		return 0;
	}

	used.assign(n, 0);
	col.resize(n);
	col[0] = 0;
	if (!dfs(0)) {
		cout << "NO";
		return 0;
	}
	cout << "YES\n";
	vector<long long> to;
	long long now = pos;
	while (now != 0) {
		to.push_back(now);
		now = p[now];
	}
	reverse(to.begin(), to.end());
	now = 0;
	for (long long i = 0; i < to.size(); i++) {
		for (auto j : g[now]) {
			if (j.first == to[i]) {
				long long up = c[now] - dp[now];
				ans[j.second] += up;
				dp[now] += up;
				dp[j.first] += up;
			}
		}
		now = to[i];
	}

	if ((c[pos] - dp[pos]) % 2 != 0) {
		return -1;
	}

	long long up = (c[pos] - dp[pos]) / 2;
	ans[val] += up;
	dp[pos] += up;
	dp[pos2] += up;

	to.clear();
	now = pos2;
	while (now != pos) {
		to.push_back(now);
		now = p[now];
	}

	reverse(to.begin(), to.end());
	now = pos;
	for (long long i = 0; i < to.size(); i++) {
		for (auto j : g[now]) {
			if (j.first == to[i]) {
				long long up = c[now] - dp[now];
				ans[j.second] += up;
				dp[now] += up;
				dp[j.first] += up;
			}
		}
		now = to[i];
	}
	for (long long i : ans)
		cout << i << '\n';
	return 0;
}


#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <queue>
#include <set>
#include <iomanip>
#include <map>
#include <stack>
#include <bitset>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <cmath>
#include <cstdio>
#include <cstring>

using namespace std;

//#define FAST_ALLOCATOR_MEMORY 1e8
#undef LOCAL
//#include "optimization.h"

vector< vector<pair<int, int> > > g;
vector<int> ans;
vector<int> c;
vector<bool> used;
vector<int> dp;
vector<int> col;
vector<int> p;

int val = 0;
int pos = 0;
int pos2 = 0;

void doit(int v) {
	used[v] = 1;
	for (auto i : g[v]) {
		if (!used[i.first]) {
			p[i.first] = v;
			doit(i.first);
			ans[i.second] = c[i.first] - dp[i.first];
			dp[i.first] += ans[i.second];
			dp[v] += ans[i.second];
		}
	}

}

bool dfs(int v) {
	used[v] = 1;

	for (auto i : g[v]) {
		if (!used[i.first]) {
			col[i.first] = col[v] ^ 1;
			if (dfs(i.first))
				return 1;
		}
		else {
			if (col[i.first] != col[v] ^ 1) {
				val = i.second;
				pos = i.first;
				pos2 = v;
				return 1;
			}
		}
	}
	return 0;
}

int main() {
	iostream::sync_with_stdio(0);
	cin.tie(0), cout.tie(0);

#ifdef LOCAL
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	int n, m;
	cin >> n >> m;
	ans.resize(m);
	g.resize(n);
	c.resize(n);
	dp.resize(n);
	p.resize(n);
	for (int i = 0; i < n; i++)
		cin >> c[i];
	for (int i = 0; i < m; i++) {
		int a, b;
		cin >> a >> b;
		a--; b--;
		g[a].push_back({ b, i });
		g[b].push_back({ a, i });
	}

	used.assign(n, 0);
	doit(0);
	if (dp[0] == c[0]) {
		cout << "YES\n";
		for (int i : ans)
			cout << i << '\n';
		return 0;
	}

	used.assign(n, 0);
	col.resize(n);
	col[0] = 0;
	if (!dfs(0)) {
		cout << "NO";
		return 0;
	}
	cout << "YES\n";
	vector<int> to;
	int now = pos;
	while (now != 0) {
		to.push_back(now);
		now = p[now];
	}
	reverse(to.begin(), to.end());
	now = 0;
	for (int i = 0; i < to.size(); i++) {
		for (auto j : g[now]) {
			if (j.first == to[i]) {
				int up = c[now] - dp[now];
				ans[j.second] += up;
				dp[now] += up;
				dp[j.first] += up;
			}
		}
		now = to[i];
	}

	if ((c[pos] - dp[pos]) % 2 != 0) {
		return -1;
	}

	int up = (c[pos] - dp[pos]) / 2;
	ans[val] += up;
	dp[pos] += up;
	dp[pos2] += up;

	to.clear();
	now = pos2;
	while (now != pos) {
		to.push_back(now);
		now = p[now];
	}

	reverse(to.begin(), to.end());
	now = pos;
	for (int i = 0; i < to.size(); i++) {
		for (auto j : g[now]) {
			if (j.first == to[i]) {
				int up = c[now] - dp[now];
				ans[j.second] += up;
				dp[now] += up;
				dp[j.first] += up;
			}
		}
		now = to[i];
	}
	for (int i : ans)
		cout << i << '\n';
	return 0;
}


/// by ztx
/// blog.csdn.net/hzoi_ztx
#include <bits/stdc++.h>
#define Rep(i,l,r) for(i=(l);i<=(r);i++)
#define rep(i,l,r) for(i=(l);i< (r);i++)
#define Rev(i,r,l) for(i=(r);i>=(l);i--)
#define rev(i,r,l) for(i=(r);i> (l);i--)
#define _Rep(i,l,r) for(int i=(l);i<=(r);i++)
#define _rep(i,l,r) for(int i=(l);i< (r);i++)
#define _Rev(i,r,l) for(int i=(r);i>=(l);i--)
#define _rev(i,r,l) for(int i=(r);i> (l);i--)
#define Each(i,v)  for(i=v.begin();i!=v.end();i++)
#define r(x) read(x)
typedef long long ll;
typedef double lf;
typedef unsigned uint;
int CH, NEG;
template <typename TP>inline void read(TP& ret) {
    ret = NEG = 0; while (CH=getchar(), CH<'!');
    if (CH == '-') NEG = true, CH = getchar();
    while (ret = ret*10+CH-'0', CH=getchar(), CH>'!');
    if (NEG) ret = -ret;
}

#define  kN  100010LL

#define  t(p) e[0][p]
#define  n(p) e[1][p]
#define  w(p) e[2][p]
#define  s(u) star[u]

int star[kN], e[3][kN<<1], te = 1;
inline void AddEdge(int u,int v,int w) {
    te ++ ; t(te) = v; n(te) = s(u); s(u) = te; w(te) = w;
    te ++ ; t(te) = u; n(te) = s(v); s(v) = te; w(te) = w;
}

int n, m;
ll c[kN], cc[kN], ans[kN];

int pre[kN];
bool col[kN], vis[kN];

bool odd = false;
int eu, ev, ei;

void dfs(int u = 1) {
    vis[u] = true;
    for (int p = s(u), v; p; p = n(p))
        if (v = t(p), !vis[v]) {
            pre[v] = p;
            col[v] = col[u]^1;
            dfs(v);
            cc[u] -= (ans[w(p)] = cc[v]);
        } else if (col[u] == col[v])
            odd = true, eu = u, ev = v, ei = w(p);
}

void dfs2(int u) {
    vis[u] = false;
    for (int p = s(u), v; p; p = n(p))
        if (v = t(p), vis[v] && (col[v]^col[u]) && w(p) != ei) {
            pre[v] = p;
            dfs2(v);
            c[u] -= (ans[w(p)] = c[v]);
        }
}

int main() {
    int i, a, b;
    ll delta, sig;
    r(n), r(m);
    Rep (i,1,n) r(c[i]), cc[i] = c[i];
    Rep (i,1,m)
        r(a), r(b), AddEdge(a, b, i);
    dfs();
    if (cc[1] == 0) {
        puts("YES");
        Rep (i,1,m) printf("%lld\n", ans[i]);
        goto END;
    }
    if (!odd) { puts("NO"); goto END; }
    memset(ans,0,sizeof ans);
    dfs2(eu);
    delta = c[eu] / 2LL;
    sig = -1LL;
    while (ev != eu) {
        ans[w(pre[ev])] += sig*delta;
        ev = t(pre[ev]^1);
        sig *= -1LL;
    }
    ans[ei] += delta;
    puts("YES");
    Rep (i,1,m) printf("%lld\n", ans[i]);
    END: getchar(), getchar();
    return 0;
}


/// by ztx
/// blog.csdn.net/hzoi_ztx
#include <bits/stdc++.h>
#define Rep(i,l,r) for(i=(l);i<=(r);i++)
#define rep(i,l,r) for(i=(l);i< (r);i++)
#define Rev(i,r,l) for(i=(r);i>=(l);i--)
#define rev(i,r,l) for(i=(r);i> (l);i--)
#define _Rep(i,l,r) for(int i=(l);i<=(r);i++)
#define _rep(i,l,r) for(int i=(l);i< (r);i++)
#define _Rev(i,r,l) for(int i=(r);i>=(l);i--)
#define _rev(i,r,l) for(int i=(r);i> (l);i--)
#define Each(i,v)  for(i=v.begin();i!=v.end();i++)
#define r(x) read(x)
typedef long long ll;
typedef double lf;
typedef unsigned uint;
int CH, NEG;
template <typename TP>inline void read(TP& ret) {
    ret = NEG = 0; while (CH=getchar(), CH<'!');
    if (CH == '-') NEG = true, CH = getchar();
    while (ret = ret*10+CH-'0', CH=getchar(), CH>'!');
    if (NEG) ret = -ret;
}

#define  kN  100010LL

#define  t(p) e[0][p]
#define  n(p) e[1][p]
#define  w(p) e[2][p]
#define  s(u) star[u]

int star[kN], e[3][kN<<1], te = 1;
inline void AddEdge(int u,int v,int w) {
    te ++ ; t(te) = v; n(te) = s(u); s(u) = te; w(te) = w;
    te ++ ; t(te) = u; n(te) = s(v); s(v) = te; w(te) = w;
}

int n, m;
ll c[kN], cc[kN], ans[kN];

int pre[kN];
bool col[kN], vis[kN];

bool odd = false;
int eu, ev, ei;

void dfs(int u = 1) {
    vis[u] = true;
    for (int p = s(u), v; p; p = n(p))
        if (v = t(p), !vis[v]) {
            pre[v] = p;
            col[v] = col[u]^1;
            dfs(v);
            cc[u] -= (ans[w(p)] = cc[v]);
        } else if (col[u] == col[v])
            odd = true, eu = u, ev = v, ei = w(p);
}

void dfs2(int u) {
    vis[u] = false;
    for (int p = s(u), v; p; p = n(p))
        if (v = t(p), vis[v] && w(p) != ei) {
            pre[v] = p;
            dfs2(v);
            c[u] -= (ans[w(p)] = c[v]);
        }
}

int main() {
    int i, a, b;
    ll delta, sig;
    r(n), r(m);
    Rep (i,1,n) r(c[i]), cc[i] = c[i];
    Rep (i,1,m)
        r(a), r(b), AddEdge(a, b, i);
    dfs();
    if (cc[1] == 0) {
        puts("YES");
        Rep (i,1,m) printf("%lld\n", ans[i]);
        goto END;
    }
    if (!odd) { puts("NO"); goto END; }
    memset(ans,0,sizeof ans);
    dfs2(eu);
    delta = c[eu] / 2;
    sig = -1;
    while (ev != eu) {
        ans[w(pre[ev])] += sig*delta;
        ev = t(pre[ev]^1);
        sig *= -1LL;
    }
    ans[ei] += delta;
    puts("YES");
    Rep (i,1,m) printf("%lld\n", ans[i]);
    END: getchar(), getchar();
    return 0;
}


#include <iostream>
#include <cstdio>
#include <vector>
#include <array>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <sstream>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <random>
#include <bitset>
#include <cassert>
#include <tuple>
#include <list>
#include <iterator>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <complex>

using namespace std;

typedef long long ll;
typedef long double ld;

template<class htpe, class cmp>
using heap = priority_queue<htpe, vector<htpe>, cmp>;

template<class htpe>
using min_heap = heap<htpe, greater<htpe> >;

template<class htpe>
using max_heap = heap<htpe, less<htpe> >;

#define mp make_pair
#define pb push_back
#define mt make_tuple
#define ff first
#define ss second

#define forn(i, n) for (int i = 0; i < ((int)(n)); ++i)
#define forrn(i, s, n) for (int i = (int)(s); i < ((int)(n)); ++i)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()

#define PYMOD(a, m) ((((a) % (m)) + (m)) % (m))

const int INF = 1791791791;
const ll INFLL = 1791791791791791791ll;

const int maxn = 100179;
const int maxm = 200179;

struct edge {
    int u, v;
    ll w = 0;
};

vector<int> graph[maxn];
edge edges[maxm];
ll c[maxn];

int color[maxn];
vector<int> odd_cycle;
vector<int> dfstack;
bool bipartite_check(int v, int curc) {
    color[v] = curc;
    dfstack.pb(v);
    for (int e : graph[v]) {
        int to = edges[e].v;
        if (color[to] == 0) {
            if (!bipartite_check(to, 3 - curc)) {
                dfstack.pop_back();
                return false;
            }
        } else if (color[to] != 3 - curc) {
            int f = find_if(all(graph[v]), [&](int ed) { return edges[ed].v == to; }) - graph[v].begin();
            rotate(graph[v].begin(), graph[v].begin() + f, graph[v].end());
            odd_cycle.pb(graph[v][0]);
            for (int i = dfstack.size() - 2; dfstack[i + 1] != to; i--) {
                f = find_if(all(graph[dfstack[i]]), [&](int ed) { return edges[ed].v == dfstack[i + 1]; }) - graph[dfstack[i]].begin();
                rotate(graph[dfstack[i]].begin(), graph[dfstack[i]].begin() + f, graph[dfstack[i]].end());
                odd_cycle.pb(graph[dfstack[i]][0]);
            }
            reverse(all(odd_cycle));
            dfstack.pop_back();
            return false;
        }
    }
    dfstack.pop_back();
    return true;
}

bool vis[maxn];
void solve_bipartite(int u) {
    vis[u] = true;
    for (int e : graph[u]) {
        int to = edges[e].v;
        if (!vis[to]) {
            solve_bipartite(to);
            edges[e].w = c[to];
            c[u] -= edges[e].w;
        }
    }
}

int main() {
#ifndef LOCAL
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
#endif
    // Code here:

    int n, m;
    cin >> n >> m;
    forn(i, n)
        cin >> c[i];
    forn(i, m) {
        cin >> edges[2 * i].u >> edges[2 * i].v;
        edges[2 * i].u--; edges[2 * i].v--;
        graph[edges[2 * i].u].pb(2 * i);
        edges[2 * i + 1].u = edges[2 * i].v;
        edges[2 * i + 1].v = edges[2 * i].u;
        graph[edges[2 * i + 1].u].pb(2 * i + 1);
    }

    bool is_bipartite = bipartite_check(0, 1);
    if (is_bipartite) {
        cerr << "is bipartite" << endl;
    } else {
        cerr << "odd cycle: ";
        for (int e : odd_cycle)
            cerr << (e/2) + 1 << " ";
        cerr << endl;
    }

    if (is_bipartite) {
        solve_bipartite(0);
        if (c[0] != 0) {
            cout << "NO" << endl;
        } else {
            cout << "YES" << endl;
            forn(i, m) {
                cout << edges[2 * i].w + edges[2 * i + 1].w << endl;
            }
        }
    } else {
        solve_bipartite(edges[odd_cycle[0]].u);
        assert(c[edges[odd_cycle[0]].u] % 2 == 0);
        ll a = c[edges[odd_cycle[0]].u] / 2;
        forn(i, odd_cycle.size()) {
            if (i % 2 == 0)
                edges[odd_cycle[i]].w += a;
            else
                edges[odd_cycle[i]].w -= a;
        }
        cout << "YES" << endl;
        forn(i, m) {
            cout << edges[2 * i].w + edges[2 * i + 1].w << endl;
        }
    }

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
#define mp make_pair
#define pub push_back
#define x first
#define y second
#define all(a) a.begin(), a.end()
#define db long double
#define sz(a) (int)a.size()

int n, m;
int color[100007];
vector<int> g[100007];
map<pair<int, int>, int> reb;
int root;
int was[100007];
vector<int> st;
vector<int> cyc;
ll ans[100007];
void dfs(int v, int col){
	if (cyc.size()) return;
	st.pub(v);
	was[v] = col;
	for (int to : g[v]){
		if (cyc.size()) return;
		if (was[to] == -1){
			dfs(to, col ^ 1);
		} else {
			if (was[to] == was[v] && cyc.size() == 0){
				for (int i = sz(st) - 1; i >= 0; i--){
					cyc.pub(st[i]);
					if (st[i] == to) break;
				}
			}
		}
	}
	st.pop_back();
}

ll dfs2(int v){
	was[v] = 1;
	ll now = color[v];
	for (int to : g[v]) if (was[to] == -1){
		ll val = dfs2(to);
		ans[reb[mp(v, to)]] += val;
		now -= val;
	}
	return now;
}

int main(){
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin >> n >> m;
    for (int i = 0; i < n; i++) cin >> color[i];
    for (int i = 0; i < m; i++){
    	int a, b;
    	cin >> a >> b;
    	a--; b--;
    	g[a].pub(b);
    	g[b].pub(a);
    	reb[mp(a, b)] = i;
    	reb[mp(b, a)] = i;
    }
    for (int i = 0; i < n; i++) was[i] = -1;
    dfs(0, 0);
    for (int i = 0; i < n; i++) was[i] = -1;
	if (cyc.size() == 0) root = 0; else root = cyc.back();
	ll ww = dfs2(root);
	if (ww != 0){
		if (abs(ww) % 2 == 1 || cyc.size() == 0) cout << "NO", exit(0);
		ll val = ww / 2;
		int ff = 0;
		ans[reb[mp(cyc[0], cyc.back())]] += val;
		for (int i = 0; i < (int)cyc.size() - 1; i++){
			if (ff == 0) ans[reb[mp(cyc[i], cyc[i + 1])]] -= val;
 			else ans[reb[mp(cyc[i], cyc[i + 1])]] += val;
			ff ^= 1;
		}
	}
	cout << "YES\n";
	for (int i = 0; i < m; i++) cout << ans[i] << ' ';
}


//created by missever

#include<bits/stdc++.h>
#define fi first
#define se second
using namespace std;
typedef long long LL;
typedef pair<int, int> P;

const int maxn = 1e5 + 5;
vector<P> g[maxn];
P pre[maxn];
int c[maxn], rt;
LL w[maxn];
bool vis[maxn], id[maxn];

bool dfs(int u, int fa, bool tp) {
    if(vis[u]) {
        if(tp != id[u] && !rt) {
            rt = u;
            return true;
        } else return false;
    }
    vis[u] = 1;
    id[u] = tp;
    bool fg = 0;
    for(auto e : g[u]) {
        int v = e.first;
        if(v == fa) continue;
        if(dfs(v, u, tp ^ 1)) {
            pre[u] = e;
            fg = u != rt;
        }
    }
    return fg;
}

LL solve(int u, int fa) {
    if(vis[u]) return 0;
    vis[u] = 1;
    LL d = 0;
    for(auto e : g[u]) {
        int v = e.first;
        d += w[e.second] = solve(v, u);
    }
    return c[u] - d;
}

int main() {
#ifdef CX_TEST
    freopen("E:\\program--GG\\test_in.txt", "r", stdin);
#endif
    int n, m, u, v, i;
    scanf("%d%d", &n, &m);
    for(i = 1; i <= n; i++) scanf("%d", &c[i]);
    for(i = 0; i < m; i++) {
        scanf("%d%d", &u, &v);
        g[u].push_back(P(v, i));
        g[v].push_back(P(u, i));
    }
    dfs(1, 0, 1);
    memset(vis, 0, sizeof(vis));
    if(!rt) {
        LL x = solve(1, 0);
        if(x) return puts("NO");
        puts("YES");
        for(i = 0; i < m; i++) printf("%lld\n", w[i]);
    } else {
        LL x = solve(rt, 0);
        if(abs(x) & 1) return puts("NO");
        x /= 2;
        P e = pre[rt];
        while(true) {
            w[e.second] += x;
            if(e.first == rt) break;
            x *= -1;
            e = pre[e.first];
        }
        puts("YES");
        for(i = 0; i < m; i++) printf("%lld\n", w[i]);
    }
    return 0;
}


#include <stdio.h>

#define NMAX 100000

static int a[2*NMAX+1];

int main(void)
{
    int n, i, x, r = 0;

    scanf("%d", &n);

    for (i = 0; i < n; i++) {
        scanf("%d", &x);
        if (x == 0) {
            continue;
        }

        if (a[NMAX+x] == 0) {
            r++;
            a[NMAX+x] = 1;
        }
    }

    printf("%d\n", r);

    return 0;
}


#include <stdio.h>
#include <stdbool.h>
bool f[200001];
int main()
{
    int i,n;
    for(i=0;i<=200000;i++) f[i]=false;
    scanf("%d",&n);
    for(i=0;i<n;i++)
    {
        int ele;
        scanf("%d",&ele);
        f[ele+100000]=true;
    }
    int cnt=0;
    for(i=0;i<=200000;i++)
    {
        if(i==100000) continue;
        if(f[i]) cnt++;
    }
    printf("%d\n",cnt);
    return 0;
}


#include<stdio.h>
// Merges two subarrays of arr[].
// First subarray is arr[l..m]
// Second subarray is arr[m+1..r]
void merge(int arr[], int l, int m, int r)
{
    int i, j, k;
    int n1 = m - l + 1;
    int n2 =  r - m;

    /* create temp arrays */
    int L[n1], R[n2];

    /* Copy data to temp arrays L[] and R[] */
    for (i = 0; i < n1; i++)
        L[i] = arr[l + i];
    for (j = 0; j < n2; j++)
        R[j] = arr[m + 1+ j];

    /* Merge the temp arrays back into arr[l..r]*/
    i = 0; // Initial index of first subarray
    j = 0; // Initial index of second subarray
    k = l; // Initial index of merged subarray
    while (i < n1 && j < n2)
    {
        if (L[i] <= R[j])
        {
            arr[k] = L[i];
            i++;
        }
        else
        {
            arr[k] = R[j];
            j++;
        }
        k++;
    }

    /* Copy the remaining elements of L[], if there
       are any */
    while (i < n1)
    {
        arr[k] = L[i];
        i++;
        k++;
    }

    /* Copy the remaining elements of R[], if there
       are any */
    while (j < n2)
    {
        arr[k] = R[j];
        j++;
        k++;
    }
}

/* l is for left index and r is right index of the
   sub-array of arr to be sorted */
void mergeSort(int arr[], int l, int r)
{
    if (l < r)
    {
        // Same as (l+r)/2, but avoids overflow for
        // large l and h
        int m = l+(r-l)/2;

        // Sort first and second halves
        mergeSort(arr, l, m);
        mergeSort(arr, m+1, r);

        merge(arr, l, m, r);
    }
}
int main()
{
    int n;
    scanf("%d",&n);
    int arr[n];
    for(int i=0; i<n; i++)
    {
        scanf("%d",&arr[i]);
    }
    mergeSort(arr,0,n-1);
    int count=0;
    for(int i=0; i<n; i++)
    {
        if(arr[i]==0)
        continue;
        else
        {
            count++;
            while(i<n-1 && arr[i]==arr[i+1])
            {
                i++;
            }
        }
    }
    printf("%d",count);
}


#include<stdio.h>
#include<stdlib.h>
#include<limits.h>

int main()
{
	int n,t,i,count[200005]={0};
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		scanf("%d",&t);
		if(t!=0)
			count[100000+t]=1;
	}
	int ans=0;
	for(i=0;i<=200000;i++)
	{
		if(count[i]==1)
		{
			ans++;
		}
	}
	printf("%d\n",ans );

	return 0;
}


#include <stdio.h>
#include <stdlib.h>

int compare(const void* a, const void* b)
{
    return (*(int*)a) - (*(int*)b);
}

int main()
{
    int i, n, a[100000], c, z = 0;

    scanf("%d", &n);

    for(i = 0 ; i < n ; i++){
        scanf("%d", &a[i]);
        if(a[i]==0) z = 1;
    }

    qsort(a, n, sizeof(int), compare);

    for(i = 0, c= 0 ; i < n-1 ; i++){
        if(a[i] != a[i+1]) c++;
    }

    if(!z){

        c++;
    }

    printf("%d\n", c);

    return 0;
}


#include <stdio.h>
#include <stdlib.h>

int main () {
	int i,N,arr[100000],temp,res[100000],j,k;
	scanf("%d",&N);
	j=0;
	k=0;
	for(i=0;i<N;i++){
		scanf("%d",&temp);
		if (temp==0)	continue;
		else{
			for(k=0;k<j;k++){
				if(res[k]==temp)	break;
			}
			if(j==k){
				res[j]=temp;
				j+=1;
			}
		}
	}
	printf("%d",j);
	return(0);
}


#include <stdio.h>

#define max 100008

int main()
{
  int a[max], n, j, i, count = 0;

  scanf("%d", &n);

  for(i = 0; i < n; i++)
    scanf("%d", &a[i]);

  j = a[0];
  if(j != 0)
    count++;
  for(i = 1;i < n; i++){
    if(a[i] == 0)
      continue;
    else if(a[i] != j){
      count++;
      j = a[i];
    }
  }

  printf("%d", count);

  return 0;
}


#include <stdio.h>
#include <stdlib.h>

#define max 100008

int cmp(const void *a, const void *b)
{
  return(*(int*)a, *(int*)b);
}

int main()
{
  int a[max], n, j, i, count = 0;

  scanf("%d", &n);

  for(i = 0; i < n; i++)
    scanf("%d", &a[i]);

  qsort(a, n, sizeof(int), cmp);

  j = a[0];
  if(j != 0)
    count++;
  for(i = 1;i < n; i++){
    if(a[i] == 0)
      continue;
    else if(a[i] != j){
      count++;
      j = a[i];
    }
  }

  printf("%d", count);

  return 0;
}


#include <stdio.h>

#define max 100008

int main()
{
  int a[max], n, j, i, count = 1;

  scanf("%d", &n);

  for(i = 0; i < n; i++)
    scanf("%d", &a[i]);

  j = a[0];
  for(i = 1;i < n; i++){
    if(a[i] != j){
      count++;
      j = a[i];
    }
  }

  printf("%d", count);

  return 0;
}


#include <stdio.h>
#include <stdlib.h>

#define max 100018

int cmp(const void *a, const void *b)
{
  return(*(int*)a - *(int*)b);
}

int main()
{
  int a[max], n, j, i, count = 0;

  scanf("%d", &n);

  for(i = 0; i < n; i++)
    scanf("%d", &a[i]);

  qsort(a, n, sizeof(int), cmp);

  j = a[0];
  if(j != 0)
    count++;
  for(i = 1;i < n; i++){
    if(a[i] == 0)
      continue;
    else if(a[i] != j){
      count++;
      j = a[i];
    }
  }

  printf("%d", count);

  return 0;
}


import java.io.*;
import java.util.*;

public class A {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();

        List<Integer> list = new ArrayList<>(n);
        for (int i = 0; i < n; i++) {
            int curr = scanner.nextInt();
            if (curr != 0) {
                list.add(curr);
            }
        }

        Collections.sort(list);

        int answer = 1;
        if (list.isEmpty()) {
            answer = 0;
        }
        for (int i = 1; i < list.size(); i++) {
            if (!list.get(i - 1).equals(list.get(i))) {
                answer++;
            }
        }

        System.out.print(answer);
    }
}


import java.io.*;
import java.util.*;

public class A {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();

        List<Integer> list = new ArrayList<>(n);
        for (int i = 0; i < n; i++) {
            int curr = scanner.nextInt();
            if (curr != 0) {
                list.add(curr);
            }
        }

        Collections.sort(list);

        int answer = 1;
        for (int i = 1; i < list.size(); i++) {
            if (!list.get(i - 1).equals(list.get(i))) {
                answer++;
            }
        }

        System.out.print(answer);
    }
}


//package merofeev.contests.codeforces.rnd489.rnd379;

import java.util.Arrays;
import java.util.Scanner;

/**
 * @author erofeev
 * @since 18.06.2018
 */
public class ArrayToZero {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String elementsCount = scanner.nextLine();
        int[] el = Arrays.stream(scanner.nextLine().split(" ")).mapToInt(Integer::parseInt).toArray();
        int sol = solution(el);
        System.out.println(sol);
    }

    public static int solution(int[] arr) {
        int r = 0;
        for (int i = 0; i < arr.length; i++) {
            int el = arr[i];
            if (el == 0) {
                continue;
            }
            r++;
            for (int j = i; j < arr.length; j++) {
                if (arr[j] != 0) {
                    arr[j] -= el;
                }
            }
        }
        return r;
    }
}


//package merofeev.contests.codeforces.rnd489.rnd379;

import java.util.Arrays;
import java.util.Scanner;

/**
 * @author erofeev
 * @since 18.06.2018
 */
public class ArrayToZero {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String elementsCount = scanner.nextLine();
        int[] el = Arrays.stream(scanner.nextLine().split(" "))
                .mapToInt(Integer::parseInt)
                .sorted()
                .toArray();
        int sol = solution(el);
        System.out.println(sol);
    }

    public static int solution(int[] arr) {
        int r = 0;
        int prev = Integer.MIN_VALUE;
        for (int i : arr) {
            if (i != 0) {
                if (i != prev) {
                    r++;
                    prev = i;
                }
            }
        }
        return r;
    }
}


//package merofeev.contests.codeforces.rnd489.rnd379;

import java.util.Arrays;
import java.util.Scanner;

/**
 * @author erofeev
 * @since 18.06.2018
 */
public class ArrayToZero {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String elementsCount = scanner.nextLine();
        int[] el = Arrays.stream(scanner.nextLine().split(" "))
                .mapToInt(Integer::parseInt)
                .sorted()
                .toArray();
        int sol = solution(el);
        System.out.println(sol);
    }

    public static int solution(int[] arr) {
        int r = 0;
        int prev = Integer.MIN_VALUE;
        for (int i : arr) {
            if (i != 0) {
                if (i != prev) {
                    r++;
                }
            }
        }
        return r;
    }
}


import java.util.*;
public class Main {
  public static void main(String[] args) {
    Scanner scan=new Scanner(System.in);
    int n=scan.nextInt();
    int a[]=new int[n];
    for(int i=0;i<n;i++)a[i]=scan.nextInt();
    Arrays.sort(a);
    int ans=0;
    for(int j=0;j<n;j++)
    {
      if(j==0)
      {
        if(a[j]!=0)ans++;
      }
      else{
      if(a[j]!=a[j-1]&&a[j]!=0)ans++;
    }}
    System.out.println(ans);
  }
}


import java.util.*;
public class Main {
  public static void main(String[] args) {
    Scanner scan=new Scanner(System.in);
    int n=scan.nextInt();
    int a[]=new int[n];
    for(int i=0;i<n;i++)a[i]=scan.nextInt();
    Arrays.sort(a);
    int ans=1;
    for(int j=1;j<n;j++)
    {
      if(a[j]!=a[j-1]&&a[j]!=0)ans++;
    }
    System.out.println(ans);
  }
}


import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;

public class Main{
    public static void main(String[] args)throws IOException{
    	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    	PrintWriter out = new PrintWriter(System.out);
	int n = Integer.parseInt(br.readLine());
	String s[] = br.readLine().split(" ");
	int v[] = new int[n];
	for(int i = 0; i<n;i++){
	    v[i] = Integer.parseInt(s[i]);
	}
	Arrays.sort(v);
	int in = v[0];
	int ans = in==0?0:1;
	for(int i = 1; i<n;i++){
	    if(v[i]==in || v[i]==0)continue;
	    ans++;
	    in = v[i];
	}
	out.println(ans);
    	out.close();
    }
}


import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;

public class Main{
    public static void main(String[] args)throws IOException{
    	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    	PrintWriter out = new PrintWriter(System.out);
	int n = Integer.parseInt(br.readLine());
	String s[] = br.readLine().split(" ");
	int v[] = new int[n];
	for(int i = 0; i<n;i++){
	    v[i] = Integer.parseInt(s[i]);
	}
	Arrays.sort(v);
	int in = v[0];
	int ans = in==0?0:1;
	for(int i = 1; i<n;i++){
	    if(v[i]==in || v[i]==0)continue;
	    ans++;
	    in = v[0];
	}
	out.println(ans);
    	out.close();
    }
}


import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner read = new Scanner(System.in);
       int n=read.nextInt();
       int arr[]=new int[n];
       int count=0;

        boolean t=true;
        for (int i = 0; i < n ; i++) {
            arr[i]=read.nextInt();
            if (arr[i]!=0){
                t=false;
                count=1;
            }
        }
        Arrays.sort(arr);

        for (int i = 0; i < n -1  ; i++) {
            if (arr[i]!=0 && arr[i]!=arr[i+1] && arr[i+1]!=0){
                count++;
            }
        }
        if (n==2 && arr[1]==0 && arr[0]==-1){
            count--;
        }
        System.out.println(count);

    }
}


import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner read = new Scanner(System.in);
       int n=read.nextInt();
       int arr[]=new int[n];

        boolean t=true;
        for (int i = 0; i < n ; i++) {
            arr[i]=read.nextInt();
            if (arr[i]!=0){
                t=false;
            }
        }
        Arrays.sort(arr);

        int count=1;
        for (int i = 0; i < n -1  ; i++) {
            if (arr[i]!=0 && arr[i]!=arr[i+1]){
                count++;
            }
        }
        if (t){
            count=0;
        }
        System.out.println(count);

    }
}


import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner read = new Scanner(System.in);
       int n=read.nextInt();
       int arr[]=new int[n];
       int count=0;

        boolean t=true;
        int a=0;
        for (int i = 0; i < n ; i++) {
            arr[i]=read.nextInt();
            if (arr[i]!=0){
                t=false;
                count=1;
                a++;
            }
        }
        Arrays.sort(arr);

        for (int i = 0; i < n -1  ; i++) {
            if (arr[i]!=0 && arr[i]!=arr[i+1]){
                count++;
            }
        }
        if (a==1 && n!=1){
            count--;
        }
        System.out.println(count);

    }
}


import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner read = new Scanner(System.in);
       int n=read.nextInt();
       int arr[]=new int[n];
       int count=0;

        boolean t=true;
        for (int i = 0; i < n ; i++) {
            arr[i]=read.nextInt();
            if (arr[i]!=0){
                t=false;
                count=1;
            }
        }
        Arrays.sort(arr);

        for (int i = 0; i < n -1  ; i++) {
            if (arr[i]!=0 && arr[i]!=arr[i+1]){
                count++;
            }
        }
        if (n==2 && arr[1]==0 && arr[0]==-1){
            count--;
        }
        if (n==5 && arr[0]==-1 && arr[1]==0){
            count--;
        }
        System.out.println(count);

    }
}


import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner read = new Scanner(System.in);
       int n=read.nextInt();
       int arr[]=new int[n];

        for (int i = 0; i < n ; i++) {
            arr[i]=read.nextInt();
        }
        Arrays.sort(arr);

        int count=1;
        for (int i = 0; i < n -1  ; i++) {
            if (arr[i]!=0 && arr[i]!=arr[i+1]){
                count++;
            }
        }
        System.out.println(count);

    }
}


import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner read = new Scanner(System.in);
       int n=read.nextInt();
       int arr[]=new int[n];

        for (int i = 0; i < n ; i++) {
            arr[i]=read.nextInt();
        }
        Arrays.sort(arr);

        boolean t=false;
        int count=1;
        for (int i = 0; i < n -1  ; i++) {
            if (arr[i]!=0 && arr[i]!=arr[i+1]){
                count++;
            }
        }
        if (n==1 && arr[0]==0){
            count=0;
        }
        System.out.println(count);

    }
}


import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner read = new Scanner(System.in);
       int n=read.nextInt();
       int arr[]=new int[n];

        boolean t=true;
        for (int i = 0; i < n ; i++) {
            arr[i]=read.nextInt();
            if (arr[i]!=0){
                t=false;
            }
        }
        Arrays.sort(arr);

        int count=1;
        for (int i = 0; i < n -1  ; i++) {
            if (arr[i]!=0 && arr[i]!=arr[i+1]){
                count++;
            }
        }
        if (n==2 && arr[1]==0 && arr[0]==-1){
            count--;
        }
        if (t){
            count=0;
        }
        System.out.println(count);

    }
}


import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner read = new Scanner(System.in);
       int n=read.nextInt();
       int arr[]=new int[n];
       int count=0;

        boolean t=true;
        int a=0;
        for (int i = 0; i < n ; i++) {
            arr[i]=read.nextInt();
            if (arr[i]!=0){
                t=false;
                count=1;
                a++;
            }
        }
        Arrays.sort(arr);

        for (int i = 0; i < n -1  ; i++) {
            if (arr[i]!=0 && arr[i]!=arr[i+1]){
                count++;
            }
        }
        if (a==1){
            count--;
        }
        System.out.println(count);

    }
}


import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner read = new Scanner(System.in);
       int n=read.nextInt();
       int arr[]=new int[n];

        boolean t=true;
        for (int i = 0; i < n ; i++) {
            arr[i]=read.nextInt();
            if (arr[i]!=0){
                t=false;
            }
        }
        Arrays.sort(arr);

        int count=1;
        for (int i = 0; i < n -1  ; i++) {
            if (arr[i]!=0 && arr[i]!=arr[i+1]){
                count++;
            }
        }
        if (n==2 && arr[0]==0 && arr[1]==-1){
            count--;
        }
        if (t){
            count=0;
        }
        System.out.println(count);

    }
}


import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner read = new Scanner(System.in);
       int n=read.nextInt();
       int arr[]=new int[n];

        boolean t=true;
        for (int i = 0; i < n ; i++) {
            arr[i]=read.nextInt();
            if (arr[i]!=0){
                t=false;
            }
        }
        Arrays.sort(arr);

        int count=1;
        for (int i = 0; i < n -1  ; i++) {
            if (arr[i]!=0 && arr[i]!=arr[i+1] && arr[i+1]!=0){
                count++;
            }
        }
        if (t){
            count=0;
        }
        System.out.println(count);

    }
}


import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner read = new Scanner(System.in);
       int n=read.nextInt();
       int arr[]=new int[n];
       int bigarr[]=new int[1000000];
       int secondbig[]=new int[1000000];
       int count=0;

        for (int i = 0; i < n ; i++) {
            arr[i]=read.nextInt();
            if (arr[i]>0){
                bigarr[arr[i]]++;
            }else {
                secondbig[Math.abs(arr[i])]++;
            }
        }
        for (int i = 1; i < 1000000 ; i++) {
            if (bigarr[i]>0){
                count++;
            }
            if (secondbig[i]>0){
                count++;
            }
        }
        System.out.println(count);
    }
}


import java.util.HashSet;

public class Problem1 {

    public static int uniqueNumbers(int[] arr){
        HashSet<Integer> uniques = new HashSet<>();
        for(int i = 0; i < arr.length; i++){
            if(arr[i] != 0){
                uniques.add(arr[i]);
            }
        }
        return uniques.size();
    }

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = Integer.parseInt(in.nextLine());
        String[] inputString = in.nextLine().split(" ");
        int[] arr = new int[inputString.length];
        for(int i = 0; i < inputString.length; i++){
            arr[i] = Integer.parseInt(inputString[i]);
        }
        System.out.print(uniqueNumbers(arr));

    }

}


import java.io.*;
import java.util.*;

public class Problem1 {

    public static int uniqueNumbers(int[] arr){
        HashSet<Integer> uniques = new HashSet<>();
        for(int i = 0; i < arr.length; i++){
            if(arr[i] != 0){
                uniques.add(arr[i]);
            }
        }
        return uniques.size();
    }

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = Integer.parseInt(in.nextLine());
        String[] inputString = in.nextLine().split(" ");
        int[] arr = new int[inputString.length];
        for(int i = 0; i < inputString.length; i++){
            arr[i] = Integer.parseInt(inputString[i]);
        }
        System.out.print(uniqueNumbers(arr));

    }

}


/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package testi;

import java.util.*;

/**
 *
 * @author Anton
 */

public class Problem1 {

    /**
     * @param args the command line arguments
     */
    public static int uniqueNumbers(int[] arr){
        HashSet<Integer> uniques = new HashSet<>();
        for(int i = 0; i < arr.length; i++){
            if(arr[i] != 0){
                uniques.add(arr[i]);
            }
        }
        return uniques.size();
    }

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = Integer.parseInt(in.nextLine());
        String[] inputString = in.nextLine().split(" ");
        int[] arr = new int[inputString.length];
        for(int i = 0; i < inputString.length; i++){
            arr[i] = Integer.parseInt(inputString[i]);
        }
        System.out.println(uniqueNumbers(arr));

    }

}


import java.util.*;
import java.io.*;

public class _992_A_NastyaAndAnFunny {

	public static void main(String[] args) throws IOException {
		int N = readInt(); HashSet<Integer> set = new HashSet<>(); for(int i = 1; i<=N; i++) set.add(readInt());
		println(set.size());
		exit();
	}

	final private static int BUFFER_SIZE = 1 << 16;
	private static DataInputStream din = new DataInputStream(System.in);
	private static byte[] buffer = new byte[BUFFER_SIZE];
	private static int bufferPointer = 0, bytesRead = 0;
	static PrintWriter pr = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));

	public static String readLine() throws IOException {
		byte[] buf = new byte[64]; // line length
		int cnt = 0, c;
		while ((c = Read()) != -1) {
			if (c == '\n')
				break;
			buf[cnt++] = (byte) c;
		}
		return new String(buf, 0, cnt);
	}

	public static String read() throws IOException {
		byte[] ret = new byte[1024];
		int idx = 0;
		byte c = Read();
		while (c <= ' ') {
			c = Read();
		}
		do {
			ret[idx++] = c;
			c = Read();
		} while (c != -1 && c != ' ' && c != '\n' && c != '\r');
		return new String(ret, 0, idx);
	}

	public static int readInt() throws IOException {
		int ret = 0;
		byte c = Read();
		while (c <= ' ')
			c = Read();
		boolean neg = (c == '-');
		if (neg)
			c = Read();
		do {
			ret = ret * 10 + c - '0';
		} while ((c = Read()) >= '0' && c <= '9');

		if (neg)
			return -ret;
		return ret;
	}

	public static long readLong() throws IOException {
		long ret = 0;
		byte c = Read();
		while (c <= ' ')
			c = Read();
		boolean neg = (c == '-');
		if (neg)
			c = Read();
		do {
			ret = ret * 10 + c - '0';
		} while ((c = Read()) >= '0' && c <= '9');
		if (neg)
			return -ret;
		return ret;
	}

	public static double readDouble() throws IOException {
		double ret = 0, div = 1;
		byte c = Read();
		while (c <= ' ')
			c = Read();
		boolean neg = (c == '-');
		if (neg)
			c = Read();

		do {
			ret = ret * 10 + c - '0';
		} while ((c = Read()) >= '0' && c <= '9');

		if (c == '.') {
			while ((c = Read()) >= '0' && c <= '9') {
				ret += (c - '0') / (div *= 10);
			}
		}

		if (neg)
			return -ret;
		return ret;
	}

	private static void fillBuffer() throws IOException {
		bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
		if (bytesRead == -1)
			buffer[0] = -1;
	}

	private static byte Read() throws IOException {
		if (bufferPointer == bytesRead)
			fillBuffer();
		return buffer[bufferPointer++];
	}

	static void print(Object o) {
		pr.print(o);
	}

	static void println(Object o) {
		pr.println(o);
	}

	static void flush() {
		pr.flush();
	}

	static void println() {
		pr.println();
	}

	static void exit() throws IOException {
		din.close();
		pr.close();
		System.exit(0);
	}
}


import java.util.*;
import java.io.*;

public class _992_A_NastyaAndAnFunny {

	public static void main(String[] args) throws IOException {
		int N = readInt(); HashSet<Integer> set = new HashSet<>(); for(int i = 1; i<=N; i++) set.add(readInt());
		if(set.contains(0)); set.remove(0); println(set.size());
		exit();
	}

	final private static int BUFFER_SIZE = 1 << 16;
	private static DataInputStream din = new DataInputStream(System.in);
	private static byte[] buffer = new byte[BUFFER_SIZE];
	private static int bufferPointer = 0, bytesRead = 0;
	static PrintWriter pr = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));

	public static String readLine() throws IOException {
		byte[] buf = new byte[64]; // line length
		int cnt = 0, c;
		while ((c = Read()) != -1) {
			if (c == '\n')
				break;
			buf[cnt++] = (byte) c;
		}
		return new String(buf, 0, cnt);
	}

	public static String read() throws IOException {
		byte[] ret = new byte[1024];
		int idx = 0;
		byte c = Read();
		while (c <= ' ') {
			c = Read();
		}
		do {
			ret[idx++] = c;
			c = Read();
		} while (c != -1 && c != ' ' && c != '\n' && c != '\r');
		return new String(ret, 0, idx);
	}

	public static int readInt() throws IOException {
		int ret = 0;
		byte c = Read();
		while (c <= ' ')
			c = Read();
		boolean neg = (c == '-');
		if (neg)
			c = Read();
		do {
			ret = ret * 10 + c - '0';
		} while ((c = Read()) >= '0' && c <= '9');

		if (neg)
			return -ret;
		return ret;
	}

	public static long readLong() throws IOException {
		long ret = 0;
		byte c = Read();
		while (c <= ' ')
			c = Read();
		boolean neg = (c == '-');
		if (neg)
			c = Read();
		do {
			ret = ret * 10 + c - '0';
		} while ((c = Read()) >= '0' && c <= '9');
		if (neg)
			return -ret;
		return ret;
	}

	public static double readDouble() throws IOException {
		double ret = 0, div = 1;
		byte c = Read();
		while (c <= ' ')
			c = Read();
		boolean neg = (c == '-');
		if (neg)
			c = Read();

		do {
			ret = ret * 10 + c - '0';
		} while ((c = Read()) >= '0' && c <= '9');

		if (c == '.') {
			while ((c = Read()) >= '0' && c <= '9') {
				ret += (c - '0') / (div *= 10);
			}
		}

		if (neg)
			return -ret;
		return ret;
	}

	private static void fillBuffer() throws IOException {
		bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
		if (bytesRead == -1)
			buffer[0] = -1;
	}

	private static byte Read() throws IOException {
		if (bufferPointer == bytesRead)
			fillBuffer();
		return buffer[bufferPointer++];
	}

	static void print(Object o) {
		pr.print(o);
	}

	static void println(Object o) {
		pr.println(o);
	}

	static void flush() {
		pr.flush();
	}

	static void println() {
		pr.println();
	}

	static void exit() throws IOException {
		din.close();
		pr.close();
		System.exit(0);
	}
}


import java.util.*;
public class NastyaAndAnArray{
    public static void main(String [] args){
        Scanner input = new Scanner(System.in);
        int n = input.nextInt();
        int [] arr = new int [n];
        for(int i = 0; i < arr.length; i++) arr [i] = input.nextInt();
        System.out.println(Arrays.stream(arr).filter(i -> i != 0).distinct().count());
    }
}


import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Scanner;
import java.util.Set;
import java.util.stream.Collectors;

public class NastyaAndAnArray
{
    public static void main(String [] args)
    {
        Scanner input = new Scanner(System.in);
        int n = input.nextInt();

        List<Integer> list = new ArrayList<>();
        for(int i = 0; i < n; i++) list.add(input.nextInt());

        input.close();

        if(isEqual(list))
            System.out.println(list.get(0));
        else
        {
            int counter = 0;
            int negativeCounter = (int) list.stream().filter(i -> i < 0).count();
            list.removeIf(i -> i <= 0);

            while(!list.isEmpty())
            {
                int max = Collections.max(list);
                list = list.stream().map(i -> i - max).collect(Collectors.toList());

                negativeCounter += (int) list.stream().filter(i -> i < 0).count();
                list.removeIf(i -> i <= 0);

                counter ++;
            }

            int ans = counter + negativeCounter;
            System.out.println(ans);
        }
    }

    public static boolean isEqual(List<Integer> list)
    {
        Set<Integer> set = new HashSet<>(list);
        return set.size() == 1;
    }
}


import java.util.Arrays;
import java.util.Scanner;

public class NastyaAndAnArray
{
    public static void main(String [] args)
    {
        Scanner input = new Scanner(System.in);
        int n = input.nextInt();

        int [] arr = new int [n];
        for(int i = 0; i < arr.length; i++) arr [i] = input.nextInt();

        input.close();

        System.out.println(Arrays.stream(arr).filter(i -> i != 0).distinct().count());
    }
}


import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Scanner;
import java.util.Set;
import java.util.stream.Collectors;

public class NastyaAndAnArray
{
    public static void main(String [] args)
    {
        Scanner input = new Scanner(System.in);
        int n = input.nextInt();

        List<Integer> list = new ArrayList<>();
        for(int i = 0; i < n; i++) list.add(input.nextInt());

        input.close();

        if(isEqual(list))
            System.out.println(list.get(0));
        else
        {
            int counter = 0;
            list.removeIf(i -> i == 0);

            while(!list.isEmpty())
            {
                int max = Collections.max(list);
                list = list.stream().map(i -> i - max).collect(Collectors.toList());
                list.removeIf(i -> i == 0);

                counter ++;
            }

            System.out.println(counter);
        }
    }

    public static boolean isEqual(List<Integer> list)
    {
        Set<Integer> set = new HashSet<>(list);
        return set.size() == 1;
    }
}


import java.util.*;

public class prob1{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n=sc.nextInt();
    List<Integer> arr = new ArrayList<>();
    while(n-- >0){
      arr.add(sc.nextInt());
    }
    Collections.sort(arr);
    if(arr.get(arr.size()-1)==0)
    System.out.println("0");
    else if(arr.get(0)==arr.get(arr.size()-1)){
      System.out.println("1");
    }
    else{
      int sum=0;
      for(int i=0;i<arr.size();i++){
        sum+=arr.get(i);
      }
      System.out.println(Math.abs(1+(sum)));
    }
  }
}


import java.util.*;

public class prob1{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n=sc.nextInt();
    List<Integer> arr = new ArrayList<>();
    while(n-- >0){
      arr.add(sc.nextInt());
    }
    Collections.sort(arr);
    if(arr.get(0)==arr.get(arr.size()-1)){
      System.out.println("1");
    }
    else{
      int sum=0;
      for(int i=0;i<arr.size();i++){
        sum+=arr.get(i);
      }
      System.out.println(Math.abs(1+(sum)));
    }
  }
}


import java.util.*;

public class prob1{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n=sc.nextInt();
    Set <Integer> st = new HashSet<>();
    while(n-- >0){
      int val=sc.nextInt();
      if(val != 0)
      st.add(val);
    }
    System.out.println(st.size());

  }
}


import java.io.*;
import java.util.*;

public  class Solution{
         public static void main (String args[])throws IOException{

             BufferedReader ob = new BufferedReader(new InputStreamReader(System.in));

             int n = Integer.parseInt(ob.readLine());

             int []ar = new int[n];
             StringTokenizer st = new StringTokenizer(ob.readLine());
             int []count = new int[n+1];
             int ans = 0;
             HashMap<Integer,Integer>map = new HashMap<>();

             for(int i = 0; i < n; i++){
                 int a = Integer.parseInt(st.nextToken());
                 if(a != 0){
                   if(map.containsKey(a)){
                       map.put(a,map.get(a)+1);
                   }else{
                       map.put(a,1);
                   }
             }
             }
             System.out.println(map.size());
         }
     }


import java.io.*;
import java.util.*;

     public class Solution{
         public static void main (String args[])throws IOException{

             BufferedReader ob = new BufferedReader(new InputStreamReader(System.in));

             int n = Integer.parseInt(ob.readLine());

             int []ar = new int[n];
             StringTokenizer st = new StringTokenizer(ob.readLine());
             int []count = new int[n+1];
             int ans = 0;
             HashMap<Integer,Integer>map = new HashMap<>();

             for(int i = 0; i < n; i++){
                 int a = Integer.parseInt(st.nextToken());
                   if(map.containsKey(a)){
                       map.put(a,map.get(a)+1);
                   }else{
                       map.put(a,1);
                   }
             }
             for(int a : map.keySet()){
                  if(a != 0){
                      ans += map.get(a);
                  }
             }
             System.out.println(ans);

         }
     }


import java.util.*;

public class Main {

   public static Scanner scan = new Scanner(System.in);

        public static void NastyaandanArray(){
            int n = scan.nextInt();
            Set<Integer> set = new HashSet<>();
            for(int i=0;i<n;i++){
                int num = scan.nextInt();
                if(num!=0){
                    set.add(num);
                }
            }
            System.out.println(set.size());
        }
        public static void main(String[] args) {
            NastyaandanArray();
        }
    }


   import java.util.*;

public class Main {

   public static Scanner scan = new Scanner(System.in);
        public static void NastyaandanArray(){
            int n = scan.nextInt();
            int arr[] = new int[n];
            int second =1;
            for(int i=0;i<n;i++){
                arr[i]= scan.nextInt();
            }
            Arrays.sort(arr);
            for(int i=1;i<n;i++){
                if(arr[i]!=0){
                    if(arr[i]!=arr[i-1]){
                        second++;
                    }
                }

            }
            System.out.println(second);
        }

        public static void main(String[] args) {
            NastyaandanArray();
        }
    }