QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#692406#8544. Colorful Graph 2sdmrlhWA 1ms7704kbC++141.1kb2024-10-31 14:28:072024-10-31 14:28:07

Judging History

你现在查看的是最新测评结果

  • [2024-10-31 14:28:07]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:7704kb
  • [2024-10-31 14:28:07]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define sf(x) scanf("%lld",&x)
#define sff(x,y) scanf("%lld%lld",&x,&y)
#define endl '\n'
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define pf(x) printf("%lld",x)
#define pii pair<int,int> 
#define f first 
#define s second
#define int long long



//
const int N = 1e6+10;
int h[N],ne[N],e[N],idx;
//
void add(int a,int b)
{
	ne[idx]=h[a],e[idx]=b,h[a]=idx++;
}

void bfs(string &now)
{
	queue<int>qu;
	now[0]='R';
	qu.push(1);
	
	while(qu.size())
	{
		int t =qu.front();
		qu.pop();
		
		for(int i=h[t];~i;i=ne[i])
		{
			int j=e[i];
			
			if(now[j-1]!='Z') continue;
			now[j-1]='R'+'B'-now[t-1];
			qu.push(j);
		}
	}
}
//


void solve()
{
	int m,n;
	cin>>m>>n;
	string res(m,'Z');
	for(int i=1;i<=4*m;i++) h[i]=-1;
	while(n--)
	{
		int a,b;
		cin>>a>>b;
		add(a,b);
		add(b,a);
	}
	
	for(int i=0;i<m;i++)
	{
		int x=i+1,y=(i+1)%m+1;
		add(x,y);
		add(y,x);
	}
	bfs(res);
	
	cout<<res<<endl;
}	
signed main()
{
	IOS;
	int _=1;
	cin>>_;
	while(_--)
		solve();
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 7704kb

input:

3
3 0
4 1
1 3
6 3
0 2
2 4
4 0

output:

RBB
RBBB
RBRRRB

result:

wrong answer cycle detected (test case 2)