QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#572689#8544. Colorful Graph 2wangjinghengWA 60ms3852kbC++14912b2024-09-18 15:58:072024-09-18 15:58:07

Judging History

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

  • [2024-09-18 15:58:07]
  • 评测
  • 测评结果:WA
  • 用时:60ms
  • 内存:3852kb
  • [2024-09-18 15:58:07]
  • 提交

answer

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

void solve(){
	int n,m;cin>>n>>m;
	vector<int> c(n+1);
	vector<pair<int,pair<int,int> > > g;
	for(int i=1;i<=m;i++){
		int u,v;cin>>u>>v;
		int x=(u-v)%n;
		x=(x+n)%n;
		int y=(v-u)%n;
		y=(y+n)%n;
		x=min(x,y);
			g.push_back({x,{v,u}});
	}
	sort(g.begin(),g.end());
	for(auto [_,e]:g){
		auto [u,v]=e;
		if(c[u]&&c[v]) continue;
		if(c[u]){
			c[v]=3-c[u];
		} 
		else if(c[v]){
			c[u]=3-c[v];
		}
		else{
			c[u]=1,c[v]=2;
		}
	}
	int cc=0; 
	for(int i=0;i<n;i++){
		if(!c[i]){
			cc=(i-1+n)%n;
			if(c[cc]){
				c[i]=3-c[cc];
			} 
			else if(c[(i+1)%n]){
				c[i]=3-c[(i+1)%n];
			}
			else c[i]=1;
		}
		if(c[i]==1){
			cout<<"B";
		}
		else if(c[i]==2){
			cout<<"R";
		}

	}
			cout<<"\n";
}
signed main(){
ios::sync_with_stdio(false);
cin.tie(0);cout.tie(0);
	int T;cin>>T;
	while(T--)
	solve(); 
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3636kb

input:

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

output:

BRB
RRBB
BRRBRB

result:

ok ok (3 test cases)

Test #2:

score: -100
Wrong Answer
time: 60ms
memory: 3852kb

input:

100000
9 6
2 0
4 6
3 6
0 6
0 7
2 6
3 0
5 2
2 4
2 0
6 3
1 5
4 1
2 4
9 6
3 1
6 4
8 1
3 6
1 6
8 6
3 0
7 4
3 0
4 0
6 4
3 1
7 4
5 1
5 0
3 1
1 4
4 1
1 3
6 3
2 4
4 0
2 0
6 3
3 0
1 3
5 3
7 4
0 5
2 5
5 1
3 5
8 5
4 1
5 1
5 0
1 3
5 7
3 0
8 5
0 2
4 6
0 6
0 3
4 0
8 5
5 1
1 4
5 0
3 1
5 7
3 0
10 7
0 2
9 2
5 8
3 9
...

output:

BRRRRBBRB
BRB
BRRBB
RRRBBB
BBRRBRRBR
BRB
BBRRBRR
BBRRRRB
RRBB
BRRBRB
RRBBRR
RRRRBBR
BRBBBRBB
BRB
RBBBRBBR
BBRRRRBB
BRB
RBBBBBBRRR
RRBBRBBB
BBBBRRBBBR
BBBBBRRRRR
RBBBRBBRBB
BRB
RRRBBRB
BBRRRR
BRRBBBBB
RRBB
RBBRBBR
BBBBBRRRRR
RRRRBBB
RRBRRBBB
BBRRRR
BRRBBR
BRB
BRB
BBRRRBBBR
RRRBBRR
RRBBR
BBRRBBBRRR
BB...

result:

wrong answer cycle detected (test case 47)