QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#134873#6634. Central SubsetPhantomThreshold#WA 1ms3528kbC++201.1kb2023-08-05 09:36:172023-08-05 09:36:21

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 09:36:21]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3528kb
  • [2023-08-05 09:36:17]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
void mian()
{
	int n,m;
	cin>>n>>m;
	vector<int> pa(n+5);
	function<int(int)> find=[&](int x){return pa[x]?pa[x]=find(pa[x]):x;};
	vector<vector<int>> G(n+5);
	for(int i=1;i<=m;i++)
	{
		int u,v;
		cin>>u>>v;
		int pu=find(u),pv=find(v);
		if(pu!=pv)
		{
			G[u].push_back(v),G[v].push_back(u);
			pa[pv]=pu;
		}
	}
	vector<int> dep(n+5);
	function<void(int)> dfs=[&](int u)
	{
		for(auto v:G[u])
		{
			if(not dep[v])
			{
				dep[v]=dep[u]+1;
				dfs(v);
			}
		}
	};
	dep[1]=1;
	dfs(1);
	int s=sqrt(n);
	while(s*s<n)s++;
	vector<vector<int>> dg(s+5);
	for(int i=1;i<=n;i++)
	{
		dg[dep[i]%n].push_back(i);
	}
	for(int i=0;i<s;i++)
	{
		if((int)dg[i].size()==0)
		{
			cout<<1<<"\n";
			cout<<1<<"\n";
			return;
		}
		if((int)dg[i].size()<=s)
		{
			cout<<dg[i].size()<<"\n";
			for(auto x:dg[i])
				cout<<x<<' ';
			cout<<"\n";
			return;
		}
	}
	return;
}
int main()
{
	ios_base::sync_with_stdio(false);
	int T;
	cin>>T;
	while(T--)
	{
		mian();
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 3528kb

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

result:

wrong answer Condition failed: "getMaxBfsDist(n, subset) <= csqrtn" (test case 1)