QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#216415#6634. Central Subsetsiddharthjoshi026WA 31ms3584kbC++231.2kb2023-10-15 18:09:102023-10-15 18:09:11

Judging History

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

  • [2023-10-15 18:09:11]
  • 评测
  • 测评结果:WA
  • 用时:31ms
  • 内存:3584kb
  • [2023-10-15 18:09:10]
  • 提交

answer

#include <bits/stdc++.h> 
using namespace std;
#define f first
#define s second
int main(){
	long long zz;
	cin>>zz;
	while(zz--){
		long long n,m;
		cin>>n>>m;
		vector<long long> adj[n];
		vector<bool> visited(n,0);
		vector<long long> depth(n,-1);
		set<long long> stt,poss;
		long double d = sqrtl(n);
    	long long bor = d;
   	    if(bor < d) bor++;
		for(long long i=0;i<m;i++){
		long long x,y;
		cin>>x>>y;
		x--;y--;
		adj[x].push_back(y);
		adj[y].push_back(x);
		}
		queue<int> q;
		int y=rand();
		y%=n;
		stt.insert(y);
		visited[y]=1;
		q.push(y);
		depth[y]=0;
		while(!q.empty()){
		while(!q.empty()){
			int v=q.front();
			q.pop();
			for(auto x:adj[v]){
				if(!visited[x]){
					q.push(x);
					visited[x]=1;
					depth[x]=1+depth[v];}
			}
		}
		for(int i=0;i<n;i++){
			if(depth[i]>bor){
				visited[i]=0;
				depth[i]=-1;
			}
			if(depth[i]==bor){
				poss.insert(i);
				visited[i]=0;
			}
		}
		for(auto x:poss){
			if(!visited[x]){
				stt.insert(x);
				depth[x]=0;
				visited[x]=1;
				q.push(x);
				break;
			}
		}
		}
		cout<<stt.size()<<'\n';
		for(auto x:stt){
			cout<<x<<' ';
		}
		cout<<'\n';
		
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

2
4 3
1 2
2 3
3 4
6 7
1 2
2 3
3 1
1 4
4 5
5 6
6 4

output:

2
1 3 
2
1 4 

result:

ok correct (2 test cases)

Test #2:

score: -100
Wrong Answer
time: 31ms
memory: 3584kb

input:

10000
15 14
13 12
5 4
9 8
11 12
15 14
10 9
14 13
2 3
2 1
6 5
10 11
3 4
7 6
8 7
6 5
2 1
2 4
4 6
2 3
3 5
10 9
8 3
9 4
5 6
5 10
3 2
5 4
2 7
1 2
4 3
2 1
2 1
2 1
2 1
9 8
9 8
5 4
1 2
6 5
3 4
3 2
7 8
7 6
2 1
1 2
14 13
3 10
5 6
2 9
11 4
2 3
2 1
8 7
13 6
5 4
5 12
6 7
4 3
7 14
16 15
2 3
2 1
6 10
6 9
6 4
9 11
...

output:

4
1 5 9 13 
3
0 3 4 
3
5 7 9 
1
1 
1
1 
3
1 4 7 
1
0 
3
2 6 12 
3
1 9 15 
1
13 
4
2 7 12 17 
2
0 3 
3
0 4 8 
3
2 13 14 
1
3 
4
1 5 9 13 
2
3 5 
1
0 
4
0 2 7 8 
1
9 
2
1 3 
3
0 3 6 
3
1 5 9 
2
2 15 
1
2 
4
1 5 9 13 
2
2 5 
3
3 7 14 
1
1 
1
7 
5
0 5 10 15 20 
3
1 7 12 
5
0 6 8 10 12 
5
2 6 7 8 15 
1
5...

result:

wrong answer Integer 0 violates the range [1, 6] (test case 2)