#include using namespace std; using ll=long long; using pll=pair; using tll=tuple; const ll INF=(1ll<<60); #define rep(i,n) for (ll i=0;i<(ll)(n);i++) #define all(v) v.begin(),v.end() template void chmin(T &a,T b){ if(a>b){ a=b; } } template void chmax(T &a,T b){ if(a> g; vector vis; vector v,s={}; void dfs(ll x,ll p){ v.push_back(x); vis[x]=true; for(auto &i:g[x]){ if(i==p) continue; if(!vis[i]) dfs(i,x); else{ if((ll)s.size()==0){ s=v; s.push_back(i); } } } v.pop_back(); } vector dist; void dfs(ll x){ for(auto &i:g[x]){ if(dist[i]==-1){ dist[i]=dist[x]+1; dfs(i); } } } int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); ll n; cin >> n; g.resize(n); vis.resize(n,false); map mp; vector ans(n,-1); vector a(n),b(n); rep(i,n){ cin >> a[i] >> b[i]; a[i]--; b[i]--; g[a[i]].push_back(b[i]); g[b[i]].push_back(a[i]); mp[{a[i],b[i]}]=i; mp[{b[i],a[i]}]=i; } dfs(0,-1); vector s2; bool ok=false; for(auto &i:s){ if(ok) s2.push_back(i); if(i==s.back()) ok=true; } rep(i,s2.size()){ ll x=s2[i]; ll y=s2[(i+1)%(ll)s2.size()]; if(x\n"; } }