题目
给你一个n个点,m条边的无向连通图。无自环无重边。
令k=根号n上取整。
抉择:找到一个大小为k的独立集;找到一个大小至少为k的简单环。
N<=1e5,m<=2e5
思路
每次删掉度数最小的点和它的邻居,直到最小的点度数>=k-1
如果你爸所有点删完,那证明你选出了独立集,否则,在剩下的点中,一定有大于k的简单环
代码
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 1e5+77;
bool bz[N];
int fa[N],dep[N],n,m,k;
vector<int> G[N];
void dfs(int x,int f,int d)
{
dep[x] = d;
fa[x] = f;
for(auto y:G[x])
{
if(dep[y]==0)
dfs(y,x,d+1);
if(dep[x]-dep[y]+1>=k)
{
cout<<2<<endl;
cout<<dep[x]-dep[y]+1<<endl;
cout<<y<<" ";
int z = x;
while(z!=y)
{
cout<<z<<" ";
z = fa[z];
}
exit(0);
}
}
if(!bz[x])
for(auto y:G[x])
{
bz[y] = 1;
}
}
int main()
{
scanf("%d%d",&n,&m);
while(k*k<n) k++;
for(int i=0,a,b;i<m;i++)
{
scanf("%d%d",&a,&b);
G[a].push_back(b);
G[b].push_back(a);
}
dfs(1,0,1);
cout<<1<<endl;
for(int i=1; k; i++)
{
if(bz[i]) continue;
cout<<i<<" ";
k--;
}
}