QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#135022#6634. Central Subsetlittle_brush#WA 10ms13264kbC++141.5kb2023-08-05 10:43:522023-08-05 10:43:52

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-08-05 10:43:52]
  • 评测
  • 测评结果:WA
  • 用时:10ms
  • 内存:13264kb
  • [2023-08-05 10:43:52]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;

inline int read()
{
	int x=0,f=1;
	char c=getchar();
	while(c<'0' || c>'9')
	{
		if(c=='-') f=-1;
		c=getchar();
	}
	while(c>='0' && c<='9')
	{
		x=x*10+c-'0';
		c=getchar();
	}
	return x*f;
}

const int N=2e5+5;
const int M=1e6+5;

int mother[N];
inline int Find(int x)
{
	if(mother[x]==x) return x;
	return mother[x]=Find(mother[x]);
}
int deep[N];
struct node{
	int to,last;
}tree[N*2];
int ss=1,head[N];
inline void add(int from,int to)
{
	tree[++ss].to=to;
	tree[ss].last=head[from];
	head[from]=ss;
}
inline void dfs(int from,int to)
{
	deep[to]=deep[from]+1;
	for(int i=head[to];i;i=tree[i].last)
	{
		int k=tree[i].to;
		if(k==from) continue;
		dfs(to,k);
	}
}

int n,m;
vector<int> re[N];

int main()
{
	int u,v;
	int T=read();
	while(T--)
	{
		n=read(); m=read();
		for(int i=1;i<=n;i++) head[i]=0, mother[i]=i;
		ss=1;
		for(int i=1;i<=m;i++)
		{
			u=read(); v=read();
			int k1=Find(u), k2=Find(v);
			if(k1!=k2) mother[k1]=k2, add(u,v), add(v,u);
		}
		dfs(0,1);
		int t=ceil(sqrt(n));
		for(int i=0;i<=t;i++) re[i].clear();
		for(int i=1;i<=n;i++) 
			re[deep[i]%(t+1)].push_back(i);
		bool flag=false;
		for(int i=0;i<=t;i++)
			if((int)re[i].size()<=t)
			{
				printf("%d\n",(int)re[i].size());
				for(int j=0;j<(int)re[i].size();j++) printf("%d ",re[i][j]);
				printf("\n");
				flag=true;
				break;
			}
		if(!flag) printf("-1\n");
	}
	return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 3ms
memory: 13264kb

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

result:

ok correct (2 test cases)

Test #2:

score: -100
Wrong Answer
time: 10ms
memory: 11280kb

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
5 10 15 
2
5 6 
2
5 9 
0

0

2
4 8 
0

2
5 11 
3
5 6 16 
0

3
6 12 18 
2
4 5 
2
5 9 
2
9 10 
0

3
5 10 15 
3
5 6 7 
0

2
1 9 
0

1
3 
2
4 7 
2
5 11 
2
11 12 
0

3
5 10 15 
2
4 6 
2
5 12 
1
3 
0

3
6 12 18 
4
6 7 10 12 
2
5 11 
3
7 8 9 
0

1
4 
2
4 5 
2
5 10 
3
6 7 8 
0

2
5 10 
2
5 6 
2
5 10 
1
3 ...

result:

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