Untitled
// y.ha #include <bits/stdc++.h> #define cook '\n' #define maxn 100001 #define Task "A" using namespace std; int n,u,tr[maxn],need; vector<int> nxt[maxn]; void inp() { cin >> n ; int x,y ; while ( cin >> x >> y ) { nxt[x].push_back(y) ; nxt[y].push_back(x) ; } } void write(int u,int v) { vector<int> way ; while ( u != v) { way.push_back(tr[u]) ; u = tr[u] ; } for ( int x : way ) cout << x << " " ; exit(0) ; } bool dfs(int u,bool ok) { if ( u == need ) return true ; for ( int v : nxt[u] ) { if ( tr[v] || ( v == need && !ok )) continue ; tr[v] = u ; dfs(v,1) ; } } int main() { ios_base::sync_with_stdio(0) ; cin.tie(nullptr) ; if(fopen(Task".INP","r")) { freopen(Task".INP","r",stdin); freopen(Task".OUT","w",stdout); } inp() ; for ( int i = 1; i <= n; i++ ) { memset(tr,0,n+1) ; need = i; for ( int x : nxt[i] ) if (dfs(x,0)) write(x,u) ; } return(0) ; }
Leave a Comment