QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#422056#6634. Central Subsetliuzhenhao09#WA 9ms4008kbC++20908b2024-05-26 17:37:532024-05-26 17:37:53

Judging History

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

  • [2024-05-26 17:37:53]
  • 评测
  • 测评结果:WA
  • 用时:9ms
  • 内存:4008kb
  • [2024-05-26 17:37:53]
  • 提交

answer

#include<bits/stdc++.h>
#define int long long
using namespace std;
int T,n,m,B;
vector<int>to[200010];
int fa[200010];
vector<int>ans;
int Find(int i){
	return fa[i] == i ? i : fa[i] = Find(fa[i]);
}
void Unite(int u,int v){
	u = Find(u),v = Find(v);
	if(u == v) return;
	fa[u] = v;
}
void dfs(int u,int fa,int tmp){
	if(tmp == B + 1) ans.push_back(u),tmp = 0;
	for(auto v : to[u]){
		if(v == fa) continue;
		dfs(v,u,tmp + 1);
	}
}
signed main(){
	scanf("%lld",&T);
	while(T--){
		ans.clear();
		scanf("%lld %lld",&n,&m);
		for(int i = 1; i <= n; i++) to[i].clear(),fa[i] = i;
		for(int i = 1,u,v; i <= m; i++){
			scanf("%lld %lld",&u,&v);
			if(Find(u) != Find(v)) to[u].push_back(v),to[v].push_back(u),Unite(u,v);
		}
		B = ceil(sqrt(n));
		dfs(1,0,B + 1);
		printf("%lld\n",(int)(ans.size()));
		for(auto v : ans) printf("%lld ",v);
		printf("\n");
	}
	return 0;
} 

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 4008kb

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 
1
1 

result:

ok correct (2 test cases)

Test #2:

score: -100
Wrong Answer
time: 9ms
memory: 3944kb

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:

3
1 6 11 
1
1 
3
1 6 10 
1
1 
1
1 
3
1 5 9 
1
1 
3
1 6 12 
5
1 10 9 8 7 
1
1 
4
1 7 13 19 
3
1 6 7 
3
1 10 6 
4
1 13 12 11 
1
1 
3
1 6 11 
1
1 
1
1 
2
1 9 
1
1 
2
1 4 
2
1 6 
3
1 6 12 
3
1 13 14 
1
1 
3
1 6 11 
1
1 
3
1 6 13 
1
1 
1
1 
4
1 7 13 19 
4
1 11 13 9 
3
1 6 12 
3
1 11 10 
1
1 
2
1 5 
3
1 6...

result:

wrong answer Integer 5 violates the range [1, 4] (test case 9)