#include #include #include using namespace std; const int maxn = 100005; vector graph[maxn]; vector bfs(int S) { vector path; vector visited(maxn, false); visited[S] = true; queue q; q.push(S); while(!q.empty()) { int node = q.front(); q.pop(); path.push_back(node); for(int neighbour : graph[node]) { if(!visited[neighbour]) { visited[neighbour] = true; q.push(neighbour); } } } return path; } int main() { int k; cin >> k; for(int i = 1; i < k; i++) { int a, b; cin >> a >> b; graph[a].push_back(b); graph[b].push_back(a); } vector p1 = bfs(0); for(int i = 0; i < p1.size(); i++) { cout << p1[i] << " " ; } vector p2 = bfs(k); for(int i = (int) p2.size() - 1; i >= 0; i--) { cout << p2[i] << " "; } return 0; }