Language: C++

#include<bits/stdc++.h>
using namespace std;
#define il inline
#define re register
#define debug printf("Now is Line : %d\n",__LINE__)
#define file(a) freopen(#a".in","r",stdin);freopen(#a".out","w",stdout)
//#define int long long
#define D double
#define inf 1000000000 
#define mod 1000000007
il int read() {
    re int x = 0, f = 1; re char c = getchar();
    while(c < '0' || c > '9') { if(c == '-') f = -1; c = getchar();}
    while(c >= '0' && c <= '9') x = x * 10 + c - 48, c = getchar();
    return x * f;
}
#define rep(i , a , b) for(int i = (a) , i##Limit = (b) ; i <= i##Limit ; ++ i)
#define drep(i , b , a) for(int i = (a) , i##Limit = (b) ; i >= i##Limit ; -- i)
#define Next(i, u) for(re int i = head[u]; i; i = e[i].next)
#define mem(k, p) memset(k, p, sizeof(k))
#define lb(x) (x)&(-(x))
#define ls k * 2
#define rs k * 2 + 1
#define maxn 100005 
il int Mul(int a, int b) { return 1ll * a * b % mod; }
il int Inc(int a, int b) { return (a += b) >= mod ? a - mod : a; }
il int Dec(int a, int b) { return (a -= b) < 0 ? a + mod : a; }
il int qpow(int a, int b) { int r = 1; while(b) { if(b & 1) r = Mul(r, a); a = Mul(a, a), b >>= 1; } return r; }
int n, m, head[maxn], cnt = 1, d[maxn], v[maxn], vis[maxn], col[maxn], b[maxn];
struct edge {
	int id, v, w, next;
}e[maxn << 2];
struct node {
	int a, b;
}a[maxn];
il bool cmp1(node a, node b) {
	return a.b < b.b;
}
il void add(int id, int u, int v) {
	e[++ cnt] = (edge){id, v, -1, head[u]}, head[u] = cnt;
	e[++ cnt] = (edge){id, u, -1, head[v]}, head[v] = cnt;
}
il bool cmp(edge a, edge b) {
	return a.id < b.id;
}
il void dfs(int u, int f) {
	col[u] = f, vis[u] = 1;
	Next(i, u) if(!vis[e[i].v]) dfs(e[i].v, f ^ 1);
}
int main() {
	n = read(), m = read();
	rep(i, 1, n) a[i].a = i, b[i] = a[i].b = read();
	sort(a + 1, a + n + 1, cmp1);
	rep(i, 1, m) {
		int u = read(), v = read();
		add(i, u, v);
	}
	dfs(1, 0), mem(vis, 0);
	rep(j, 1, n) {
		int flag = 0;
		if(vis[a[j].a] == 0) Next(i, a[j].a) if(col[a[j],a] != cal[e[i].v] && a[j].b == b[e[i].v]) flag = 1;
		if(vis[a[j].a] == 0 && !flag) return puts("-1"), 0;
		Next(i, a[j].a) {
			if(e[i].w != -1) continue;
			if(col[a[j].a] != col[e[i].v]) e[i].w = e[i ^ 1].w = b[e[i].v];
			else e[i].w = e[i ^ 1].w = b[e[i].v] - a[j].b;
			vis[e[i].v] = 1;
		}
	}
	rep(i, 1, n) if(col[i]) putchar('B'); else putchar('W');
	puts("");
	sort(e + 1, e + cnt + 1, cmp);
	for(re int i = 2; i <= cnt; i += 2) printf("%d\n", e[i].w == -1 ? inf : e[i].w);
	return 0;
}


Compiler output:
a.cc: In function 'int read()':
a.cc:12:12: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   12 |     re int x = 0, f = 1; re char c = getchar();
      |            ^
a.cc:12:19: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   12 |     re int x = 0, f = 1; re char c = getchar();
      |                   ^
a.cc:12:34: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   12 |     re int x = 0, f = 1; re char c = getchar();
      |                                  ^
a.cc: In function 'void dfs(int, int)':
a.cc:48:14: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   48 |         Next(i, u) if(!vis[e[i].v]) dfs(e[i].v, f ^ 1);
      |              ^
a.cc:19:31: note: in definition of macro 'Next'
   19 | #define Next(i, u) for(re int i = head[u]; i; i = e[i].next)
      |                               ^
a.cc: In function 'int main()':
a.cc:61:43: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   61 |                 if(vis[a[j].a] == 0) Next(i, a[j].a) if(col[a[j],a] != cal[e[i].v] && a[j].b == b[e[i].v]) flag = 1;
      |                                           ^
a.cc:19:31: note: in definition of macro 'Next'
   19 | #define Next(i, u) for(re int i = head[u]; i; i = e[i].next)
      |                               ^
a.cc:61:60: error: invalid types 'int [100005][node [100005]]' for array subscript
   61 |                 if(vis[a[j].a] == 0) Next(i, a[j].a) if(col[a[j],a] != cal[e[i].v] && a[j].b == b[e[i].v]) flag = 1;
      |                                                            ^
a.cc:61:72: error: 'cal' was not declared in this scope; did you mean 'col'?
   61 |                 if(vis[a[j].a] == 0) Next(i, a[j].a) if(col[a[j],a] != cal[e[i].v] && a[j].b == b[e[i].v]) flag = 1;
      |                                                                        ^~~
      |                                                                        col
a.cc:63:22: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   63 |                 Next(i, a[j].a) {
      |                      ^
a.cc:19:31: note: in definition of macro 'Next'
   19 | #define Next(i, u) for(re int i = head[u]; i; i = e[i].next)
      |                               ^
a.cc:73:20: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   73 |         for(re int i = 2; i <= cnt; i += 2) printf("%d\n", e[i].w == -1 ? inf : e[i].w);
      |                    ^