DFS一遍......
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
using namespace std;
const int maxn=100100;
bool vis[maxn];
int deep[maxn];
int n,m,k,cnt;
vector<int> edge[maxn];
vector<int> road;
bool dfs(int u,int dep)
{
vis[u]=true;
deep[u]=dep;
road.push_back(u);
for(int i=0,sz=edge[u].size();i<sz;i++)
{
int v=edge[u][i];
if(vis[v]==true&&deep[u]-deep[v]>=k)
{
int id=0;
for(int i=0;i<road.size();i++)
{
if(road[i]==v)
{
id=i; break;
}
}
printf("%d\n",road.size()-id);
for(int i=id,sz=road.size();i<sz;i++)
{
printf("%d%c",road[i],(i+1==sz)?'\n':' ');
}
return true;
}
else if(vis[v]==false)
{
if(dfs(v,dep+1)) return true;
}
}
road.pop_back();
return false;
}
int main()
{
scanf("%d%d%d",&n,&m,&k);
while(m--)
{
int a,b;
scanf("%d%d",&a,&b);
edge[a].push_back(b);
edge[b].push_back(a);
}
for(int i=1;i<=n;i++)
{
cnt=0;
if(vis[i]==false)
{
if(dfs(i,cnt)) break;
}
}
return 0;
}