https://codeforces.com/contest/1131/problem/F

#include<bits/stdc++.h>
using namespace std;
int n;
vector<vector<int> > v;
vector<int> par;
int find(int d){
if(d==par[d])
return d;
else
return par[d]=find(par[d]);
}
void unite(int x,int y){
x=find(x);
y=find(y);
if(v[x].size()<v[y].size())
swap(x,y);
for(int i=;i<v[y].size();i++)
v[x].push_back(v[y][i]);
par[y]=x;
}
int main(){
int n;
cin>>n;
v.resize(n+);
par.resize(n+);
for(int i=;i<=n;i++){
par[i]=i;
v[i].push_back(i);
}
for(int i=;i<n-;i++){
int a,b;
cin>>a>>b;
unite(a,b);
}
for(int x:v[find()])cout<<x<<' ';
cout<<endl;
return ;
}
05-11 21:54