QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#135023#6634. Central Subsetlittle_brush#RE 0ms0kbC++141.5kb2023-08-05 10:44:272023-08-05 10:44:29

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:44:29]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:0kb
  • [2023-08-05 10:44:27]
  • 提交

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;
			}
		assert(false);
		if(!flag) printf("-1\n");
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Dangerous Syscalls

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:


result: