Language: C++

///Bismillahir Rahmanir Rahim
#include "bits/stdc++.h"

#define                           ll                          long long
#define                           int                         ll
#define                           fi                          first
#define                           si                          second
#define                           mp                          make_pair
#define                           pb                          push_back
#define                           pi                          pair<ll,ll>
#define                           clr(x)                      memset(x,0,sizeof(x));
#define                           f(i,l,r)                    for(int i=l;i<=r;i++)
#define                           rf(i,r,l)                   for(int i=r;i>=l;i--)
#define                           done(i)                     cout<<"done = "<<i<<endl;
#define                           show(x,y)                   cout<<x<<" : ";for(auto z:y)cout<<z<<" ";cout<<endl;
#define                           fast                        ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

using namespace std;

const int inf=1e9;
const int mod=1e9+7;
const int M=5000005;
vector<pi>adj[M];
vector<pi>edg;
vector<int>rasta[M];
map<pi,int>yo;
int vis[M],d[M];
int dfs(int u,int par)
{
    if(par==-1)vis[u]=1;
    else
    {
        if(vis[par]==1)vis[u]=2;
        else vis[u]=1;
    }
    for(auto v:rasta[u])
    {
        if(vis[v]==0 && v!=par)dfs(v,u);
    }
}
 main()

{
    fast
    int n,m;
    cin>>n>>m;
    f(i,1,n)
    {
        cin>>d[i];
    }
    f(i,1,m)
    {
        int u,v;
        cin>>u>>v;
        adj[u].pb(mp(d[v],v));
        adj[v].pb(mp(d[u],u));
        edg.pb(mp(u,v));
    }
    f(i,1,n)
    {
        if(adj[i]size()==0)continue;
        sort(adj[i].begin(),adj[i].end());
    }
    f(i,1,n)
    {
        if(adj[i].size()==0)continue;
        int dis=adj[i][0].fi;
        int cur=d[i];
        int v=adj[i][0].si;
        if(cur<dis)
        {
            cout<<"-1"<<endl;
            return 0;
        }
        rasta[i].pb(v);
        pi tmp=mp(i,v);
        if(tmp.fi>tmp.si)swap(tmp.fi,tmp.si);
        yo[tmp]=cur;
    }
    f(i,1,n)
    {
        if(vis[i]==0)
        {
            dfs(i,-1);
        }
    }
    vector<int>ses;
    for(auto x:edg)
    {
        int u=x.fi;
        int v=x.si;
        if(u>v)swap(u,v);
        if(yo.count(mp(u,v))!=0)
        {
            ses.pb(yo[mp(u,v)]);
        }
        else ses.pb(inf);
    }
    f(i,1,n)
    {
        if(vis[i]==1)cout<<"W";
        else cout<<"B";
    }
    cout<<endl;
    for(auto x:ses)
    {
        cout<<x<<"\n";
    }
    return 0;

}





































Compiler output:
a.cc: In function 'long long int dfs(long long int, long long int)':
a.cc:40:1: warning: no return statement in function returning non-void [-Wreturn-type]
   40 | }
      | ^
a.cc: At global scope:
a.cc:41:2: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   41 |  main()
      |  ^~~~
a.cc: In function 'int main()':
a.cc:61:18: error: expected ')' before 'size'
   61 |         if(adj[i]size()==0)continue;
      |           ~      ^~~~
      |                  )
a.cc:61:17: error: could not convert 'adj[i]' from 'std::vector<std::pair<long long int, long long int> >' to 'bool'
   61 |         if(adj[i]size()==0)continue;
      |            ~~~~~^
      |                 |
      |                 std::vector<std::pair<long long int, long long int> >