QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#187731#6634. Central SubsetrsjWA 41ms17052kbC++141.1kb2023-09-24 21:28:262023-09-24 21:28:26

Judging History

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

  • [2023-09-24 21:28:26]
  • 评测
  • 测评结果:WA
  • 用时:41ms
  • 内存:17052kb
  • [2023-09-24 21:28:26]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
const int N = 2e5+10;
struct edge {
	int to;
	edge *nex;
}*head[N];

int f[N]; 
int find(int x) {
	if(f[x]==x) return x;
	return f[x]=find(f[x]);
}
void uni(int x,int y) {
	f[find(x)]=find(y);
}
bool check(int x,int y) {
	return find(x)==find(y);
}
void add(int u,int v) {
	edge *cur=new edge;
	cur->to=v;
	cur->nex=head[u];
	head[u]=cur;
}
int h[N],b;

int maxn=0;
vector<int> s[N];
void dfs(int u,int fa) {
	h[u]=h[fa]+1;
	s[h[u]].push_back(u);
	maxn=max(maxn,h[u]);
	for(edge *cur=head[u];cur;cur=cur->nex) {
		if(cur->to==fa) continue;
		dfs(cur->to,u);
	}	
}

void get() {
	maxn=0;
	int n,m,i,u,V;
	cin>>n>>m;
	b=ceil(sqrt(n));
	for(i=1;i<=n;i++) head[i]=0,f[i]=i;
	for(i=1;i<=n;i++) s[i].clear();
	for(i=1;i<=m;i++) {
		cin>>u>>V;
		if(check(u,V)) continue;
		uni(u,V);
		add(u,V),add(V,u);
	}
	dfs(1,0);
	vector<int> ans;
	ans.push_back(1);
	for(i=maxn-b;i>1;i-=b) {
		for(int x:s[i]) ans.push_back(x);
	} cout<<ans.size()<<endl;
	for(i=0;i<ans.size();i++) cout<<ans[i]<<" \n"[i==ans.size()-1];
}
int main() {
	int T; cin>>T;
	while(T--) get();
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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

result:

ok correct (2 test cases)

Test #2:

score: -100
Wrong Answer
time: 41ms
memory: 17052kb

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

result:

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