QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#216254#6634. Central Subsetsiddharthjoshi026WA 33ms3728kbC++231.4kb2023-10-15 16:57:412023-10-15 16:57:42

Judging History

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

  • [2023-10-15 16:57:42]
  • 评测
  • 测评结果:WA
  • 用时:33ms
  • 内存:3728kb
  • [2023-10-15 16:57:41]
  • 提交

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,0);
		set<long long> stt;
		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);
		}
		bool flag=1;
		set<int> poss;
		while(flag){
		stt.clear();
		poss.clear();
		queue<long long> q;
		int y=rand()%n;
		q.push(y);
		depth[y]=0;
		stt.insert(y);
		while(!q.empty()){
				while(!q.empty()){
					long long v=q.front();
					q.pop();
					visited[v]=1;
					if(depth[v]==bor){
						break;
					}
					for(auto x:adj[v]){
						if(!visited[x]){
							if(depth[v]==bor-1){
								poss.insert(x);
							}
						depth[x]=1+depth[v];
						q.push(x);
						}
					}
				}
				while(!q.empty()){
					q.pop();
				}
					for(auto x:poss){
						if(!visited[x]){
							q.push(x);
							depth[x]=0;
							visited[x]=0;
							stt.insert(x);
							break;
						}
					}
			}			
		if(stt.size()<=bor){
				for(int x=0;x<n;x++){
					if(!visited[x]&&stt.size()<bor){
						stt.insert(x);
					}
				}
		cout<<stt.size()<<'\n';
		for(auto x: stt){
			cout<<1+x<<' ';
		}
		cout<<'\n';
		flag=0;
		}
	}
	}
	return 0;
}

詳細信息

Test #1:

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

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 4 
2
3 5 

result:

ok correct (2 test cases)

Test #2:

score: -100
Wrong Answer
time: 33ms
memory: 3728kb

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 2 3 14 
2
4 5 
2
8 10 
1
2 
1
2 
3
1 2 8 
1
1 
2
3 7 
3
1 10 16 
1
14 
5
3 9 10 11 12 
1
4 
4
1 6 9 10 
4
3 14 16 17 
1
4 
4
2 7 8 9 
1
4 
1
1 
3
1 3 8 
1
10 
2
1 4 
3
1 6 7 
2
2 6 
5
1 2 4 6 16 
1
3 
4
1 6 10 15 
1
3 
2
4 8 
1
2 
1
8 
5
6 11 17 18 19 
4
2 10 11 13 
4
1 9 11 13 
4
3 7 8 11 
1
6 ...

result:

wrong answer Condition failed: "getMaxBfsDist(n, subset) <= csqrtn" (test case 1)