QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#135015#6634. Central Subsetlittle_brush#WA 11ms13096kbC++141.5kb2023-08-05 10:39:372023-08-05 10:39:39

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:39:39]
  • 评测
  • 测评结果:WA
  • 用时:11ms
  • 内存:13096kb
  • [2023-08-05 10:39:37]
  • 提交

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].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;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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
2 4 
2
3 5 

result:

ok correct (2 test cases)

Test #2:

score: -100
Wrong Answer
time: 11ms
memory: 13096kb

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
4 8 12 
2
3 4 
2
4 8 
1
2 
1
2 
3
3 6 9 
1
2 
4
4 8 10 14 
3
4 13 14 
0

4
5 10 15 20 
2
3 8 
2
4 8 
3
6 7 8 
3
3 4 5 
3
4 8 12 
2
3 4 
1
2 
2
3 4 
0

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

result:

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