QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#216370#6634. Central Subsetsiddharthjoshi026RE 0ms0kbC++231.6kb2023-10-15 17:46:532023-10-15 17:46:53

Judging History

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

  • [2023-10-15 17:46:53]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:0kb
  • [2023-10-15 17:46:53]
  • 提交

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

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Runtime Error

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:


result: