QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#187736#6634. Central SubsetrsjWA 36ms16556kbC++141.2kb2023-09-24 21:33:202023-09-24 21:33:20

Judging History

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

  • [2023-09-24 21:33:20]
  • 评测
  • 测评结果:WA
  • 用时:36ms
  • 内存:16556kb
  • [2023-09-24 21:33:20]
  • 提交

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);
		// cout<<u<<" "<<V<<endl;
	}
	dfs(2,0);
	vector<int> ans;
	ans.push_back(2);
	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() {
	// freopen("1.in","r",stdin);
	int T; cin>>T;
	while(T--) get();
	return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 2ms
memory: 10704kb

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:

1
2
3
2 3 1

result:

ok correct (2 test cases)

Test #2:

score: -100
Wrong Answer
time: 36ms
memory: 16556kb

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:

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

result:

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