比赛 csp2025模拟练习1 评测结果 AWWWWAWWWWWAWWWWAWWWWWWWWWWWWWWWWWWWAWWWWWWWWWWWWW
题目名称 彩色道路 最终得分 10
用户昵称 会挽弯弓满月 运行时间 3.176 s
代码语言 C++ 内存使用 18.14 MiB
提交时间 2025-10-28 11:54:17
显示代码纯文本
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
const int N=2e5+10;
ll read(){
	ll x=0,f=1;
	char c=getchar();
	while(c<48||c>57){
		if(c==45) f=-1;
		c=getchar();
	}
	while(c>=48&&c<=57){
		x=(x<<1)+(x<<3)+c-48;
		c=getchar();
	}
	return f*x;
}
ll n,m;
struct node{
	ll to,nxt,id;
}e[N<<1];
ll h[N],tot;
void add(ll u,ll v,ll i){
	e[++tot]={v,h[u],i};
	h[u]=tot;
	return;
}
struct que{
	ll u,v;
}s[N];
ll co[N];
bool vis[N];
void dfs(ll u,ll color){
	co[u]=color;
	ll v,id;
	for(ll i=h[u];i;i=e[i].nxt){
		v=e[i].to;id=e[i].id;
		if(co[v]!=-1) continue;
		vis[id]=1;
		dfs(v,color^1);
	}
	return;
}
void solve(){
	memset(co,-1,sizeof(co));
	for(int i=1;i<=n;i++){
		if(co[i]==-1){
			dfs(i,0);
		}
	}
	return;
}
void print(){
	for(int i=1;i<=m;i++){
		if(!vis[i]) printf("G");
		else{
			if(co[s[i].u]==0) printf("B");
			else printf("R");
		}
	}
	return;
}
int main(){
	freopen("paintoads.in","r",stdin);
	freopen("paintoads.out","w",stdout);
	n=read();m=read();
	ll u,v;
	for(int i=1;i<=m;i++){
		u=read();v=read();
		add(u,v,i);add(v,u,i);
		s[i]={u,v};
	}
	solve();
	print();
	return 0;
}