蒟蒻求救,90pts
查看原帖
蒟蒻求救,90pts
755114
CD43楼主2024/4/7 21:32

RT

#include<bits/stdc++.h>
#define endl "\n"
#define mp make_pair
#define int long long
#define ull unsigned long long
using namespace std;
const long long mod=1000000001;
const long long P=201;
int n,m,k;
bool t[1000001];
bool f;
vector<int>a[1000001];
int dfs(int x)
{
	int cnt=0;
	if(t[x]==1)return 0;
	t[x]=1;
	for(int i=0;i<a[x].size();i++)cnt+=dfs(a[x][i]);
	return cnt+1;
}
signed main()
{
	cin.tie(0);
	cout.tie(0);
	ios::sync_with_stdio(0);
//	freopen("ce.in","r",stdin);
//	freopen("ce.out","w",stdout);
	cin>>n>>m>>k;
	int x,y;
	for(int i=1;i<=m;i++)
	{
		cin>>x>>y;
		a[x].push_back(y);
		a[y].push_back(x);
	}
	if(dfs(1)!=n)
	{
		cout<<"Poor SOL!";
		return 0;
	}
	memset(t,0,sizeof t);
	for(int i=1;i<=n;i++)
	{
		if(a[i].size()<=k)
		{
			for(int j=0;j<a[i].size();j++)
			{
				cout<<a[i][j]<<' ';
				t[a[i][j]]=1;
				k--;
				f=1;
			}
		}
	}
	if(f==0)
	{
		cout<<"How oversuspicious you are, SOL!";
		return 0;
	}
	for(int i=1;k;i++)
	{
		if(t[i]==0)
		{
			t[i]=1;
			cout<<i<<' ';
			k--;
		}
	}
	return 0;
	exit(0);
}
/*

*/
2024/4/7 21:32
加载中...