#include #include #include #include #include #include #include #include #include using namespace std; #define int long long #define endl "\n" constexpr long long INF = (long long)1e18; constexpr long long MOD = 1'000'000'007; struct fast_io { fast_io(){ std::cin.tie(nullptr); std::ios::sync_with_stdio(false); }; } fio; bool cycle_detection(const vector> &G, vector &used, vector &used2, deque &C, int cur, int per){ used[cur] = true; used2[cur] = true; C.push_back(cur); for(int nex : G[cur]){ if(used[nex]){ if(used2[nex]) { if(per == nex) continue; while(C.front() != nex){ C.pop_front(); } return true; } else { continue; } } if(cycle_detection(G, used, used2, C, nex, cur)) return true; } C.pop_back(); used2[cur] = false; return false; } deque cycle_detection(const vector> &G){ int N = G.size(); vector used(N), used2(N); deque C; for(int i = 0; i < N; i++){ if(used[i] == true) continue; C.clear(); if(cycle_detection(G, used, used2, C, i, -1)) return C; } return {}; } signed main(){ cout<> G; deque c; map, int> mp; cin>>N; G.resize(N); for(int i = 0; i < N; i++){ int a, b; cin>>a>>b; a--, b--; G[a].push_back(b); G[b].push_back(a); mp[{a,b}] = i + 1; mp[{b,a}] = i + 1; } c = cycle_detection(G); cout<<(int)c.size(); for(int i = 0; i < c.size(); i++){ cout<<" "<