#include<bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
vi f,s;
int find(int u) { return u==f[u]?u: f[u]=find(f[u]); }
vvi tree;
vi *t;
int main()
{
	int n;
	cin>> n;
	f.resize(n+1);
	s.resize(n+1);
	//tree.resize(n+1);
	t= new vi[n+1];
	for(int i=1; i<= n; i++)
	{
		s[i]= i; f[i] = i; t[i].push_back(i); //tree[i].push_back(i);
	}
	for(int i=0;i<n; i++)
	{
		int a,b;
		cin>> a>> b;
		int u= find(a); int v= find(b);
		if(u==v) continue;
	//	cout<<u<<" "<<v<<endl;
		if(s[u]< s[v]) swap(u,v);
		s[u]+= s[v];
		for(auto j: t[v]) t[u].push_back(j); t[v].clear(); //t[v].shrink_to_fit();
		f[v]=u;
	}
	for(auto i: t[f[1]]) cout<<i<<" ";
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
vi f,s;
int find(int u) { return u==f[u]?u: f[u]=find(f[u]); }
vvi tree;
vi *t;
int main()
{
	int n;
	cin>> n;
	f.resize(n+1);
	s.resize(n+1);
	//tree.resize(n+1);
	t= new vi[n+1];
	for(int i=1; i<= n; i++)
	{
		s[i]= i; f[i] = i; t[i].push_back(i); //tree[i].push_back(i);
	}
	for(int i=0;i<n; i++)
	{
		int a,b;
		cin>> a>> b;
		int u= find(a); int v= find(b);
		if(u==v) continue;
	//	cout<<u<<" "<<v<<endl;
		if(s[u]< s[v]) swap(u,v);
		s[u]+= s[v];
		for(auto j: t[v]) t[u].push_back(j); t[v]=t[u];
		f[v]=u;
	}
	for(auto i: t[f[1]]) cout<<i<<" ";
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
vi f,s;
int find(int u) { return u==f[u]?u: f[u]=find(f[u]); }
vvi tree;
int main()
{
	int n;
	cin>> n;
	f.resize(n+1);
	s.resize(n+1);
	tree.resize(n+1);
	for(int i=1; i<= n; i++)
	{
		s[i]= i; f[i] = i; tree[i].push_back(i);
	}
	for(int i=0;i<n; i++)
	{
		int u,v;
		cin>> u>> v;
		 u= find(u); v= find(v);

		if(u==v) continue;
	//	cout<<u<<" "<<v<<endl;
		if(s[u]< s[v]) swap(u,v);
		s[u]+= s[v];
		for(auto j: tree[v]) tree[u].push_back(j); tree[v].clear();
		f[v]=u;
	}
	for(auto i: tree[f[1]]) cout<<i<<" ";
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
vi f,s;
int find(int u) { return u==f[u]?u: f[u]=find(f[u]); }
vvi tree;
int main()
{
	int n;
	cin>> n;
	f.resize(n+1);
	s.resize(n+1);
	tree.resize(n+1);
	for(int i=1; i<= n; i++)
	{
		s[i]= i; f[i] = i; tree[i].push_back(i);
	}
	for(int i=0;i<n; i++)
	{
		int a,b;
		cin>> a>> b;
		int u= find(a); int v= find(b);
		if(u==v) continue;
	//	cout<<u<<" "<<v<<endl;
		if(s[u]< s[v]) swap(u,v);
		s[u]+= s[v];
		for(auto j: tree[v]) tree[u].push_back(j); tree[v].clear();
		f[v]=u;
	}
	for(auto i: tree[f[1]]) cout<<i<<" ";
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
vi f,s;
int find(int u) { return u==f[u]?u: f[u]=find(f[u]); }
vvi tree;
int main()
{
	int n;
	cin>> n;
	f.resize(n+1);
	s.resize(n+1);
	tree.resize(n+1);
	for(int i=1; i<= n; i++)
	{
		s[i]= i; f[i] = i; tree[i].push_back(i);
	}
	for(int i=0;i<n; i++)
	{
		int a,b;
		cin>> a>> b;
		int u= find(a); int v= find(b);
		if(u==v) continue;
	//	cout<<u<<" "<<v<<endl;
		if(s[u]< s[v]) swap(u,v);
		s[u]+= s[v];
		for(auto j: tree[v]) tree[u].push_back(j);
		f[v]=u;
	}
	for(auto i: tree[f[1]]) cout<<i<<" ";
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
vi f,s;
int find(int u) { return u==f[u]?u: f[u]=find(f[u]); }
vvi tree;
vi *t;
int main()
{
	int n;
	cin>> n;
	f.resize(n+1);
	s.resize(n+1);
	//tree.resize(n+1);
	t= new vi[n+1];
	for(int i=1; i<= n; i++)
	{
		s[i]= i; f[i] = i; t[i].push_back(i); //tree[i].push_back(i);
	}
	for(int i=0;i<n; i++)
	{
		int a,b;
		cin>> a>> b;
		int u= find(a); int v= find(b);
		if(u==v) continue;
	//	cout<<u<<" "<<v<<endl;
		if(s[u]< s[v]) swap(u,v);
		s[u]+= s[v];
		for(auto j: t[v]) t[u].push_back(j); t[v].clear(); t[v].shrink_to_fit();
		f[v]=u;
	}
	for(auto i: t[f[1]]) cout<<i<<" ";
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
vi f,s;
int find(int u) { return u==f[u]?u: f[u]=find(f[u]); }
vvi tree;
int main()
{
	int n;
	//cin>> n;
	scanf("%d",&n);
	f.resize(n+1);
	s.resize(n+1);
	tree.resize(n+1);
	for(int i=1; i<= n; i++)
	{
		s[i]= 1; f[i] = i; tree[i].push_back(i);
	}
	for(int i=0;i<n; i++)
	{
		int u,v;
		//cin>> a>> b;
		scanf("%d %d",&u,&v);
		u= find(u); v= find(v);
		if(u==v) continue;
	//	cout<<u<<" "<<v<<endl;
		if(s[u]< s[v]) swap(u,v);
		s[u]+= s[v];
		for(auto j: tree[v]) tree[u].push_back(j); tree[v].clear();
		f[v]=u;
	}
	for(auto i: tree[find(1)]) cout<<i<<" ";
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
vi f,s;
int find(int u) { return u==f[u]?u: f[u]=find(f[u]); }
vvi tree;
int main()
{
	int n;
	cin>> n;
	f.resize(n+1);
	s.resize(n+1);
	tree.resize(n+1);
	for(int i=1; i<= n; i++)
	{
		s[i]= i; f[i] = i; tree[i].push_back(i);
	}
	for(int i=0;i<n; i++)
	{
		//int a,b;

		int u= find(a); int v= find(b);
		cin>> u>> v;
		if(u==v) continue;
	//	cout<<u<<" "<<v<<endl;
		if(s[u]< s[v]) swap(u,v);
		s[u]+= s[v];
		for(auto j: tree[v]) tree[u].push_back(j); tree[v].clear();
		f[v]=u;
	}
	for(auto i: tree[f[1]]) cout<<i<<" ";
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
vi f,s;
int find(int u) { return u==f[u]?u: f[u]=find(f[u]); }
vvi tree;
int main()
{
	int n;
	cin>> n;
	f.resize(n+1);
	s.resize(n+1);
	tree.resize(n+1);
	for(int i=1; i<= n; i++)
	{
		s[i]= i; f[i] = i; tree[i].push_back(i);
	}
	for(int i=0;i<n; i++)
	{
		int a,b;
		cin>> a>> b;
		int u= find(a); int v= find(b);
		if(u==v) continue;
		cout<<u<<" "<<v<<endl;
		if(s[u]< s[v]) swap(u,v);
		s[u]+= s[v];
		for(auto j: tree[v]) tree[u].push_back(j);
		f[v]=u;
	}
	for(auto i: tree[f[1]]) cout<<i<<" ";
	return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <unordered_set>
#include <queue>
#include <ctime>

using namespace std;

void solve();

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    solve();
    return 0;
}

int min(int a, int b) {
    if (a < b)
        return a;
    else
        return b;
}

int max(int a, int b) {
    if (a > b)
        return a;
    else
        return b;
}

int n, p[150001];
vector < vector < int > > ans(150001);

int get(int v) {
    if (p[v] == v)
        return v;
    return p[v] = get(p[v]);
}

void un(int a, int b) {
    a = get(a);
    b = get(b);
    if (ans[a].size() > ans[b].size()) {
        while (ans[b].size() > 0) {
            ans[a].push_back(ans[b][0]);
            ans[b].erase(ans[b].begin());
        }
        p[b] = a;
    } else {
        while (ans[a].size() > 0) {
            ans[b].push_back(ans[a][0]);
            ans[a].erase(ans[a].begin());
        }
        p[b] = a;
    }
}

void solve() {
    cin >> n;
    for (int i = 0; i < n; i++) {
        p[i] = i;
        ans[i].push_back(i);
    }
    for (int i = 0; i < n - 1; i++) {
        int f, s;
        cin >> f >> s;
        f--, s--;
        un(f, s);
    }
    int p = get(0);
    for (int i = 0; i < ans[p].size(); i++) {
        cout << ans[p][i] + 1 << " ";
    }
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <unordered_set>
#include <queue>
#include <ctime>

using namespace std;

void solve();

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    solve();
    return 0;
}

#define int long long

int min(int a, int b) {
    if (a < b)
        return a;
    else
        return b;
}

int max(int a, int b) {
    if (a > b)
        return a;
    else
        return b;
}

int n, p[150001];
vector < vector < int > > ans(150001);

int get(int v) {
    if (p[v] == v)
        return v;
    return p[v] = get(p[v]);
}

void un(int a, int b) {
    a = get(a);
    b = get(b);
    for (int i = 0; i < ans[b].size(); i++) {
        ans[a].push_back(ans[b][i]);
    }
    ans[b] = {0};
    p[b] = a;
}

void solve() {
    cin >> n;
    for (int i = 0; i < n; i++) {
        p[i] = i;
        ans[i].push_back(i);
    }
    for (int i = 0; i < n - 1; i++) {
        int f, s;
        cin >> f >> s;
        f--, s--;
        un(f, s);
    }
    int p = get(0);
    for (int i = 0; i < ans[p].size(); i++) {
        cout << ans[p][i] + 1 << " ";
    }
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <unordered_set>
#include <queue>
#include <ctime>

using namespace std;

void solve();

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    solve();
    return 0;
}

int min(int a, int b) {
    if (a < b)
        return a;
    else
        return b;
}

int max(int a, int b) {
    if (a > b)
        return a;
    else
        return b;
}

int n, p[150001];
vector < vector < int > > ans(150001);

int get(int v) {
    if (p[v] == v)
        return v;
    return p[v] = get(p[v]);
}

void un(int a, int b) {
    a = get(a);
    b = get(b);
    if (ans[a].size() > ans[b].size()) {
        while (ans[b].size() > 0) {
            ans[a].push_back(ans[b][0]);
            ans[b].erase(ans[b].begin());
        }
        p[b] = a;
    } else {
        while (ans[a].size() > 0) {
            ans[b].push_back(ans[a][0]);
            ans[a].erase(ans[a].begin());
        }
        p[a] = b;
    }
}

void solve() {
    cin >> n;
    for (int i = 0; i < n; i++) {
        p[i] = i;
        ans[i].push_back(i);
    }
    for (int i = 0; i < n - 1; i++) {
        int f, s;
        cin >> f >> s;
        f--, s--;
        un(f, s);
    }
    int p = get(0);
    for (int i = 0; i < ans[p].size(); i++) {
        cout << ans[p][i] + 1 << " ";
    }
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <unordered_set>
#include <queue>
#include <ctime>
#include <set>

using namespace std;

void solve();

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    solve();
    return 0;
}

#define int long long

int min(int a, int b) {
    if (a < b)
        return a;
    else
        return b;
}

int max(int a, int b) {
    if (a > b)
        return a;
    else
        return b;
}

int n, p[150001];
vector < string > ans(150001);

int get(int v) {
    if (p[v] == v)
        return v;
    return p[v] = get(p[v]);
}

void un(int a, int b) {
    a = get(a);
    b = get(b);
    ans[a] += ans[b];
    p[b] = a;
}

void solve() {
    cin >> n;
    for (int i = 0; i < n; i++) {
        p[i] = i;
        ans[i].push_back(i + '1');
    }
    for (int i = 0; i < n - 1; i++) {
        int f, s;
        cin >> f >> s;
        f--, s--;
        un(f, s);
    }
    int p = get(0);
    for (int i = 0; i < ans[p].size(); i++) {
        cout << ans[p][i] << " ";
    }
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <unordered_set>
#include <queue>
#include <ctime>

using namespace std;

void solve();

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    solve();
    return 0;
}

#define int long long

int min(int a, int b) {
    if (a < b)
        return a;
    else
        return b;
}

int max(int a, int b) {
    if (a > b)
        return a;
    else
        return b;
}

int n, p[150001];
vector < vector < int > > ans(150001);

int get(int v) {
    if (p[v] == v)
        return v;
    return p[v] = get(p[v]);
}

void un(int a, int b) {
    a = get(a);
    b = get(b);
    while (ans[b].size() > 0) {
        ans[a].push_back(ans[b][0]);
        ans[b].erase(ans[b].begin());
    }
    p[b] = a;
}

void solve() {
    cin >> n;
    for (int i = 0; i < n; i++) {
        p[i] = i;
        ans[i].push_back(i);
    }
    for (int i = 0; i < n - 1; i++) {
        int f, s;
        cin >> f >> s;
        f--, s--;
        un(f, s);
    }
    int p = get(0);
    for (int i = 0; i < ans[p].size(); i++) {
        cout << ans[p][i] + 1 << " ";
    }
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <unordered_set>
#include <queue>
#include <ctime>

using namespace std;

void solve();

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    solve();
    return 0;
}

#define int long long

int min(int a, int b) {
    if (a < b)
        return a;
    else
        return b;
}

int max(int a, int b) {
    if (a > b)
        return a;
    else
        return b;
}

int n, p[150001];
vector < vector < int > > ans(150001);

int get(int v) {
    if (p[v] == v)
        return v;
    return p[v] = get(p[v]);
}

void un(int a, int b) {
    int ran = rand() % 2;
    a = get(a);
    b = get(b);
    if (ran) {
        for (int i = 0; i < ans[b].size(); i++) {
            ans[a].push_back(ans[b][i]);
        }
        p[b] = a;
    } else {
        for (int i = 0; i < ans[a].size(); i++) {
            ans[b].push_back(ans[a][i]);
        }
        p[a] = b;
    }
}

void solve() {
    srand(time(0));
    cin >> n;
    for (int i = 0; i < n; i++) {
        p[i] = i;
        ans[i].push_back(i);
    }
    for (int i = 0; i < n - 1; i++) {
        int f, s;
        cin >> f >> s;
        f--, s--;
        un(f, s);
    }
    int p = get(0);
    for (int i = 0; i < ans[p].size(); i++) {
        cout << ans[p][i] + 1 << " ";
    }
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <unordered_set>
#include <queue>
#include <ctime>

using namespace std;

void solve();

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    solve();
    return 0;
}

#define int long long

int min(int a, int b) {
    if (a < b)
        return a;
    else
        return b;
}

int max(int a, int b) {
    if (a > b)
        return a;
    else
        return b;
}

int n, p[150001];
vector < vector < int > > ans(150001);

int get(int v) {
    if (p[v] == v)
        return v;
    return p[v] = get(p[v]);
}

void un(int a, int b) {
    a = get(a);
    b = get(b);
    for (int i = 0; i < ans[b].size(); i++) {
        ans[a].push_back(ans[b][i]);
    }
    ans[b].clear();
    p[b] = a;
}

void solve() {
    cin >> n;
    for (int i = 0; i < n; i++) {
        p[i] = i;
        ans[i].push_back(i);
    }
    for (int i = 0; i < n - 1; i++) {
        int f, s;
        cin >> f >> s;
        f--, s--;
        un(f, s);
    }
    int p = get(0);
    for (int i = 0; i < ans[p].size(); i++) {
        cout << ans[p][i] + 1 << " ";
    }
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <unordered_set>
#include <queue>
#include <ctime>
#include <set>

using namespace std;

void solve();

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    solve();
    return 0;
}

#define int long long

int min(int a, int b) {
    if (a < b)
        return a;
    else
        return b;
}

int max(int a, int b) {
    if (a > b)
        return a;
    else
        return b;
}

int n, p[150001];
vector < string > ans(150001);

int get(int v) {
    if (p[v] == v)
        return v;
    return p[v] = get(p[v]);
}

void un(int a, int b) {
    int ran = rand() % 2;
    a = get(a);
    b = get(b);
    if (ran) {
        ans[a] += ans[b];
        p[b] = a;
    } else {
        ans[b] += ans[a];
        p[a] = b;
    }
}

void solve() {
    srand(time(0));
    cin >> n;
    for (int i = 0; i < n; i++) {
        p[i] = i;
        ans[i].push_back(i + '1');
    }
    for (int i = 0; i < n - 1; i++) {
        int f, s;
        cin >> f >> s;
        f--, s--;
        un(f, s);
    }
    int p = get(0);
    for (int i = 0; i < ans[p].size(); i++) {
        cout << ans[p][i] << " ";
    }
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <unordered_set>
#include <queue>
#include <ctime>

using namespace std;

void solve();

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    solve();
    return 0;
}

int min(int a, int b) {
    if (a < b)
        return a;
    else
        return b;
}

int max(int a, int b) {
    if (a > b)
        return a;
    else
        return b;
}

int n, p[150001];
vector < vector < int > > ans(150001);

int get(int v) {
    if (p[v] == v)
        return v;
    return p[v] = get(p[v]);
}

void un(int a, int b) {
    a = get(a);
    b = get(b);
    while (ans[b].size() > 0) {
        ans[a].push_back(ans[b][0]);
        ans[b].erase(ans[b].begin());
    }
    p[b] = a;
}

void solve() {
    cin >> n;
    for (int i = 0; i < n; i++) {
        p[i] = i;
        ans[i].push_back(i);
    }
    for (int i = 0; i < n - 1; i++) {
        int f, s;
        cin >> f >> s;
        f--, s--;
        un(f, s);
    }
    int p = get(0);
    for (int i = 0; i < ans[p].size(); i++) {
        cout << ans[p][i] + 1 << " ";
    }
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <unordered_set>
#include <queue>
#include <ctime>

using namespace std;

void solve();

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    solve();
    return 0;
}

#define int long long

int min(int a, int b) {
    if (a < b)
        return a;
    else
        return b;
}

int max(int a, int b) {
    if (a > b)
        return a;
    else
        return b;
}

int n, p[150001];
vector < vector < int > > ans(150001);

int get(int v) {
    if (p[v] == v)
        return v;
    return p[v] = get(p[v]);
}

void un(int a, int b) {a = get(a);
    b = get(b);
    for (int i = 0; i < ans[b].size(); i++) {
        ans[a].push_back(ans[b][i]);
    }
    p[b] = a;
}

void solve() {
    cin >> n;
    for (int i = 0; i < n; i++) {
        p[i] = i;
        ans[i].push_back(i);
    }
    for (int i = 0; i < n - 1; i++) {
        int f, s;
        cin >> f >> s;
        f--, s--;
        un(f, s);
    }
    int p = get(0);
    for (int i = 0; i < ans[p].size(); i++) {
        cout << ans[p][i] + 1 << " ";
    }
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <unordered_set>
#include <queue>
#include <ctime>

using namespace std;

void solve();

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    solve();
    return 0;
}

#define int long long

int min(int a, int b) {
    if (a < b)
        return a;
    else
        return b;
}

int max(int a, int b) {
    if (a > b)
        return a;
    else
        return b;
}

int n, p[150001], pr[150001];
vector < vector < int > > a(150001);

int get(int v) {
    if (p[v] == v)
        return v;
    return get(p[v]);
}

int pget(int v) {
    if (pr[v] == v)
        return v;
    return pget(pr[v]);
}

void un(int a, int b) {
    int ran = rand() % 2;
    if (ran == 0) {
        b = pget(b);
        a = get(a);
        p[a] = b;
        pr[b] = a;
    } else {
        b = get(b);
        a = pget(a);
        pr[a] = b;
        p[b] = a;
    }
}

void solve() {
    srand(time(0));
    cin >> n;
    for (int i = 0; i < n; i++) {
        p[i] = i;
        pr[i] = i;
    }
    for (int i = 0; i < n - 1; i++) {
        int f, s;
        cin >> f >> s;
        f--, s--;
        un(f, s);
    }
    int u = pget(0);
    while (p[u] != u) {
        cout << u + 1 << " ";
        u = p[u];
    }
    cout << u + 1;
}


#include<algorithm>
#include<complex>
#include<ctype.h>
#include<iomanip>
#include<iostream>
#include<map>
#include<math.h>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<stdio.h>
#include<string>
#include<string>
#include<vector>

using namespace std;
typedef long long ll;

#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define br() p("")
#define pn(s) cout << (#s) << " " << (s) << endl
#define p_yes() p("YES")
#define p_no() p("NO")

template < typename T >
void vprint(T &V){
	for(auto v : V){
    	cout << v << " ";
	}
	cout << endl;
}

const ll mod = 1e9 + 7;
const ll inf = 1e18;

const int N_MAX = 150010;
ll parent[N_MAX];
vector<vector<ll> > G;
ll N;

ll findRoot(ll a){
    if(a==parent[a]){
        return a;
    }
    else{
        return parent[a] = findRoot(parent[a]);
    }
}

void printGroup(){
    br();
    FOR(i, 1, N+1){
        cout << "i=" << i << " ";
        vprint(G[i]);
    }
}

void unite(ll a, ll b){
    if(findRoot(a)==findRoot(b)){
        return;
    }

    // aの方が大きいグループとする
    if(G[a].size() < G[b].size()){
        swap(a, b);
    }

    ll rootA = findRoot(a);
    ll rootB = findRoot(b);
    parent[rootB] = rootA;

    // ll new_size = G[rootA].size() + G[rootB].size();
    // G[rootA].reserve(new_size);
    // copy(ALL(G[rootB]), back_inserter(G[rootA]));
    // G[b].clear();

    ll new_size = G[rootA].size() + G[rootB].size();
    G[rootA].reserve(new_size);
    ll L = G[rootB].size();
    FOR(i, 0, L){
        ll member = G[rootB][i];
        G[rootA].push_back(member);
    }
    // for(ll member : G[rootB]){
    //     G[rootA].push_back(member);
    // }
    G[b].clear();
    G[b].reserve(0);
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);

    // input
    cin >> N;
    G.resize(N+1);

    FOR(i, 1, N+1){
        parent[i] = i;
        G[i].push_back(i);
    }

    FOR(i, 0, N-1){
        ll x, y;
        cin >> x >> y;

        unite(x, y);
        //printGroup();
    }

    ll a = findRoot(1);
    cout << G[a][0];
    ll L = G[a].size();
    FOR(i, 1, L){
        cout << " " << G[a][i];
    }
    cout << endl;

    return 0;
}


#include<algorithm>
#include<complex>
#include<ctype.h>
#include<iomanip>
#include<iostream>
#include<map>
#include<math.h>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<stdio.h>
#include<string>
#include<string>
#include<vector>

using namespace std;
typedef long long ll;

#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define br() p("")
#define pn(s) cout << (#s) << " " << (s) << endl
#define p_yes() p("YES")
#define p_no() p("NO")

template < typename T >
void vprint(T &V){
	for(auto v : V){
    	cout << v << " ";
	}
	cout << endl;
}

const ll mod = 1e9 + 7;
const ll inf = 1e18;

const int N_MAX = 150010;
ll parent[N_MAX];
vector<vector<ll> > G;
ll N;

ll findRoot(ll a){
    if(a==parent[a]){
        return a;
    }
    else{
        return parent[a] = findRoot(parent[a]);
    }
}

void printGroup(){
    br();
    FOR(i, 1, N+1){
        cout << "i=" << i << " ";
        vprint(G[i]);
    }
}

void unite(ll a, ll b){
    if(findRoot(a)==findRoot(b)){
        return;
    }

    // aの方が大きいグループとする
    if(G[a].size() < G[b].size()){
        swap(a, b);
    }

    ll rootA = findRoot(a);
    ll rootB = findRoot(b);
    parent[rootB] = rootA;

    // ll new_size = G[rootA].size() + G[rootB].size();
    // G[rootA].reserve(new_size);
    // copy(ALL(G[rootB]), back_inserter(G[rootA]));
    // G[b].clear();

    ll new_size = G[rootA].size() + G[rootB].size();
    G[rootA].reserve(new_size);
    ll L = G[rootB].size();
    FOR(i, 0, L){
        ll member = G[rootB][i];
        G[rootA].push_back(member);
    }
    // for(ll member : G[rootB]){
    //     G[rootA].push_back(member);
    // }
    G[b].clear();
    G[b].reserve(0);
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);

    // input
    cin >> N;
    G.resize(N+1);

    FOR(i, 1, N+1){
        parent[i] = i;
        G[i].push_back(i);
    }

    FOR(i, 0, N-1){
        ll x, y;
        cin >> x >> y;

        // unite(x, y);
        //printGroup();

        ll a = x;
        ll b = y;
        if(findRoot(a)==findRoot(b)){
            continue;
        }
        // aの方が大きいグループとする
        if(G[a].size() < G[b].size()){
            swap(a, b);
        }
        ll rootA = findRoot(a);
        ll rootB = findRoot(b);
        parent[rootB] = rootA;

        ll new_size = G[rootA].size() + G[rootB].size();
        G[rootA].reserve(new_size);
        ll L = G[rootB].size();
        FOR(i, 0, L){
            ll member = G[rootB][i];
            G[rootA].push_back(member);
        }
        G[b].clear();
    }

    ll a = findRoot(1);
    cout << G[a][0];
    ll L = G[a].size();
    FOR(i, 1, L){
        cout << " " << G[a][i];
    }
    cout << endl;

    return 0;
}


#include<algorithm>
#include<complex>
#include<ctype.h>
#include<iomanip>
#include<iostream>
#include<map>
#include<math.h>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<stdio.h>
#include<string>
#include<string>
#include<vector>

using namespace std;
//typedef long long ll;
typedef int ll;

#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define br() p("")
#define pn(s) cout << (#s) << " " << (s) << endl
#define p_yes() p("YES")
#define p_no() p("NO")

template < typename T >
void vprint(T &V){
	for(auto v : V){
    	cout << v << " ";
	}
	cout << endl;
}

const ll mod = 1e9 + 7;
const ll inf = 1e18;

const int N_MAX = 150010;
ll parent[N_MAX];
vector<vector<ll> > G;
ll N;

ll findRoot(ll a){
    if(a==parent[a]){
        return a;
    }
    else{
        return parent[a] = findRoot(parent[a]);
    }
}

void printGroup(){
    br();
    FOR(i, 1, N+1){
        cout << "i=" << i << " ";
        vprint(G[i]);
    }
}

void unite(ll a, ll b){
    if(findRoot(a)==findRoot(b)){
        return;
    }

    // aの方が大きいグループとする
    if(G[a].size() < G[b].size()){
        swap(a, b);
    }

    ll rootA = findRoot(a);
    ll rootB = findRoot(b);
    parent[rootB] = rootA;

    for(ll member : G[rootB]){
        G[rootA].push_back(member);
    }
    G[b].clear();
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);

    // input
    cin >> N;
    G.resize(N+1);

    FOR(i, 1, N+1){
        parent[i] = i;
        G[i].push_back(i);
    }

    FOR(i, 0, N){
        ll x, y;
        cin >> x >> y;

        unite(x, y);
        //printGroup();
    }

    ll a = findRoot(1);
    cout << G[a][0];
    ll L = G[a].size();
    FOR(i, 1, L){
        cout << " " << G[a][i];
    }
    cout << endl;

    return 0;
}


#include<algorithm>
#include<complex>
#include<ctype.h>
#include<iomanip>
#include<iostream>
#include<map>
#include<math.h>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<stdio.h>
#include<string>
#include<string>
#include<vector>

using namespace std;
//typedef long long ll;
typedef int ll;

#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define br() p("")
#define pn(s) cout << (#s) << " " << (s) << endl
#define p_yes() p("YES")
#define p_no() p("NO")

template < typename T >
void vprint(T &V){
	for(auto v : V){
    	cout << v << " ";
	}
	cout << endl;
}

const ll mod = 1e9 + 7;
const ll inf = 1e18;

const int N_MAX = 150010;
ll parent[N_MAX];
// vector<vector<ll> > G;
vector<ll> G[N_MAX];
ll N;

ll findRoot(ll a){
    if(a==parent[a]){
        return a;
    }
    else{
        return parent[a] = findRoot(parent[a]);
    }
}

void printGroup(){
    br();
    FOR(i, 1, N+1){
        cout << "i=" << i << " ";
        vprint(G[i]);
    }
}

void unite(ll a, ll b){
    if(findRoot(a)==findRoot(b)){
        return;
    }

    // aの方が大きいグループとする
    if(G[a].size() < G[b].size()){
        swap(a, b);
    }

    ll rootA = findRoot(a);
    ll rootB = findRoot(b);
    parent[rootB] = rootA;

    // ll new_size = G[rootA].size() + G[rootB].size();
    // G[rootA].reserve(new_size);
    // copy(ALL(G[rootB]), back_inserter(G[rootA]));
    // G[b].clear();

    ll new_size = G[rootA].size() + G[rootB].size();
    G[rootA].reserve(new_size);
    ll L = G[rootB].size();
    FOR(i, 0, L){
        ll member = G[rootB][i];
        G[rootA].push_back(member);
    }
    // for(ll member : G[rootB]){
    //     G[rootA].push_back(member);
    // }
    G[b].clear();
    G[b].reserve(0);
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);

    // input
    cin >> N;
    //G.resize(N+1);

    FOR(i, 1, N+1){
        parent[i] = i;
        G[i].push_back(i);
    }

    FOR(i, 0, N){
        ll x, y;
        cin >> x >> y;

        unite(x, y);
        //printGroup();
    }

    ll a = findRoot(1);
    cout << G[a][0];
    ll L = G[a].size();
    FOR(i, 1, L){
        cout << " " << G[a][i];
    }
    cout << endl;

    return 0;
}


#include<algorithm>
#include<complex>
#include<ctype.h>
#include<iomanip>
#include<iostream>
#include<map>
#include<math.h>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<stdio.h>
#include<string>
#include<string>
#include<vector>

using namespace std;
//typedef long long ll;
typedef int ll;

#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define br() p("")
#define pn(s) cout << (#s) << " " << (s) << endl
#define p_yes() p("YES")
#define p_no() p("NO")

template < typename T >
void vprint(T &V){
	for(auto v : V){
    	cout << v << " ";
	}
	cout << endl;
}

const ll mod = 1e9 + 7;
const ll inf = 1e18;

const int N_MAX = 150010;
ll parent[N_MAX];
vector<vector<ll> > G;
ll N;

ll findRoot(ll a){
    if(a==parent[a]){
        return a;
    }
    else{
        return parent[a] = findRoot(parent[a]);
    }
}

void printGroup(){
    br();
    FOR(i, 1, N+1){
        cout << "i=" << i << " ";
        vprint(G[i]);
    }
}

void unite(ll a, ll b){
    if(findRoot(a)==findRoot(b)){
        return;
    }

    // aの方が大きいグループとする
    if(G[a].size() < G[b].size()){
        swap(a, b);
    }

    ll rootA = findRoot(a);
    ll rootB = findRoot(b);
    parent[rootB] = rootA;

    ll new_size = G[rootA].size() + G[rootB].size();
    G[rootA].reserve(new_size);
    copy(ALL(G[rootB]), back_inserter(G[rootA]));
    G[b].clear();

    // for(ll member : G[rootB]){
    //     G[rootA].push_back(member);
    // }
    // G[b].clear();
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);

    // input
    cin >> N;
    G.resize(N+1);

    FOR(i, 1, N+1){
        parent[i] = i;
        G[i].push_back(i);
    }

    FOR(i, 0, N){
        ll x, y;
        cin >> x >> y;

        unite(x, y);
        //printGroup();
    }

    ll a = findRoot(1);
    cout << G[a][0];
    ll L = G[a].size();
    FOR(i, 1, L){
        cout << " " << G[a][i];
    }
    cout << endl;

    return 0;
}


#include<algorithm>
#include<complex>
#include<ctype.h>
#include<iomanip>
#include<iostream>
#include<map>
#include<math.h>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<stdio.h>
#include<string>
#include<string>
#include<vector>

using namespace std;
//typedef long long ll;
typedef int ll;

#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define br() p("")
#define pn(s) cout << (#s) << " " << (s) << endl
#define p_yes() p("YES")
#define p_no() p("NO")

template < typename T >
void vprint(T &V){
	for(auto v : V){
    	cout << v << " ";
	}
	cout << endl;
}

const ll mod = 1e9 + 7;
const ll inf = 1e18;

const int N_MAX = 150010;
ll parent[N_MAX];
vector<vector<ll> > G;
ll N;

ll findRoot(ll a){
    if(a==parent[a]){
        return a;
    }
    else{
        return parent[a] = findRoot(parent[a]);
    }
}

void printGroup(){
    br();
    FOR(i, 1, N+1){
        cout << "i=" << i << " ";
        vprint(G[i]);
    }
}

void unite(ll a, ll b){
    if(findRoot(a)==findRoot(b)){
        return;
    }

    // aの方が大きいグループとする
    if(G[a].size() < G[b].size()){
        swap(a, b);
    }

    ll rootA = findRoot(a);
    ll rootB = findRoot(b);
    parent[rootB] = rootA;

    // ll new_size = G[rootA].size() + G[rootB].size();
    // G[rootA].reserve(new_size);
    // copy(ALL(G[rootB]), back_inserter(G[rootA]));
    // G[b].clear();

    ll new_size = G[rootA].size() + G[rootB].size();
    G[rootA].reserve(new_size);
    for(ll member : G[rootB]){
        G[rootA].push_back(member);
    }
    G[b].clear();
    G[b].reserve(0);
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);

    // input
    cin >> N;
    G.resize(N+1);

    FOR(i, 1, N+1){
        parent[i] = i;
        G[i].push_back(i);
    }

    FOR(i, 0, N){
        ll x, y;
        cin >> x >> y;

        unite(x, y);
        //printGroup();
    }

    ll a = findRoot(1);
    cout << G[a][0];
    ll L = G[a].size();
    FOR(i, 1, L){
        cout << " " << G[a][i];
    }
    cout << endl;

    return 0;
}


#include<algorithm>
#include<complex>
#include<ctype.h>
#include<iomanip>
#include<iostream>
#include<map>
#include<math.h>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<stdio.h>
#include<string>
#include<string>
#include<vector>

using namespace std;
typedef long long ll;

#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define br() p("")
#define pn(s) cout << (#s) << " " << (s) << endl
#define p_yes() p("YES")
#define p_no() p("NO")

template < typename T >
void vprint(T &V){
	for(auto v : V){
    	cout << v << " ";
	}
	cout << endl;
}

const ll mod = 1e9 + 7;
const ll inf = 1e18;

const int N_MAX = 150010;
ll parent[N_MAX];
vector<vector<ll> > G;
ll N;

ll findRoot(ll a){
    if(a==parent[a]){
        return a;
    }
    else{
        return parent[a] = findRoot(parent[a]);
    }
}

void printGroup(){
    br();
    FOR(i, 1, N+1){
        cout << "i=" << i << " ";
        vprint(G[i]);
    }
}

void unite(ll a, ll b){
    if(findRoot(a)==findRoot(b)){
        return;
    }

    // aの方が大きいグループとする
    if(G[findRoot(a)].size() < G[findRoot(b)].size()){
        swap(a, b);
    }

    ll rootA = findRoot(a);
    ll rootB = findRoot(b);
    parent[rootB] = rootA;

    for(ll member : G[rootB]){
        G[rootA].push_back(member);
    }
    G[b].clear();
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);

    // input
    cin >> N;
    G.resize(N+1);

    FOR(i, 1, N+1){
        parent[i] = i;
        G[i].push_back(i);
    }

    FOR(i, 0, N-1){
        ll x, y;
        cin >> x >> y;
        unite(x, y);
    }

    ll a = findRoot(1);
    cout << G[a][0];
    ll L = G[a].size();
    FOR(i, 1, L){
        cout << " " << G[a][i];
    }
    cout << endl;

    return 0;
}


#include<algorithm>
#include<complex>
#include<ctype.h>
#include<iomanip>
#include<iostream>
#include<map>
#include<math.h>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<stdio.h>
#include<string>
#include<string>
#include<vector>

using namespace std;
//typedef long long ll;
typedef int ll;

#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define br() p("")
#define pn(s) cout << (#s) << " " << (s) << endl
#define p_yes() p("YES")
#define p_no() p("NO")

template < typename T >
void vprint(T &V){
	for(auto v : V){
    	cout << v << " ";
	}
	cout << endl;
}

const ll mod = 1e9 + 7;
const ll inf = 1e18;

const int N_MAX = 150010;
ll parent[N_MAX];
vector<vector<ll> > G;
ll N;

ll findRoot(ll a){
    if(a==parent[a]){
        return a;
    }
    else{
        return parent[a] = findRoot(parent[a]);
    }
}

void printGroup(){
    br();
    FOR(i, 1, N+1){
        cout << "i=" << i << " ";
        vprint(G[i]);
    }
}

void unite(ll a, ll b){
    if(findRoot(a)==findRoot(b)){
        return;
    }

    // aの方が大きいグループとする
    if(G[a].size() < G[b].size()){
        swap(a, b);
    }

    ll rootA = findRoot(a);
    ll rootB = findRoot(b);
    parent[rootB] = rootA;

    // ll new_size = G[rootA].size() + G[rootB].size();
    // G[rootA].reserve(new_size);
    // copy(ALL(G[rootB]), back_inserter(G[rootA]));
    // G[b].clear();

    ll new_size = G[rootA].size() + G[rootB].size();
    G[rootA].reserve(new_size);
    ll L = G[rootB].size();
    FOR(i, 0, L){
        ll member = G[rootB][i];
        G[rootA].push_back(member);
    }
    // for(ll member : G[rootB]){
    //     G[rootA].push_back(member);
    // }
    G[b].clear();
    G[b].reserve(0);
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);

    // input
    cin >> N;
    G.resize(N+1);

    FOR(i, 1, N+1){
        parent[i] = i;
        G[i].push_back(i);
    }

    FOR(i, 0, N){
        ll x, y;
        cin >> x >> y;

        unite(x, y);
        //printGroup();
    }

    ll a = findRoot(1);
    cout << G[a][0];
    ll L = G[a].size();
    FOR(i, 1, L){
        cout << " " << G[a][i];
    }
    cout << endl;

    return 0;
}


#include<algorithm>
#include<complex>
#include<ctype.h>
#include<iomanip>
#include<iostream>
#include<map>
#include<math.h>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<stdio.h>
#include<string>
#include<string>
#include<vector>

using namespace std;
typedef long long ll;

#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define br() p("")
#define pn(s) cout << (#s) << " " << (s) << endl
#define p_yes() p("YES")
#define p_no() p("NO")

template < typename T >
void vprint(T &V){
	for(auto v : V){
    	cout << v << " ";
	}
	cout << endl;
}

const ll mod = 1e9 + 7;
const ll inf = 1e18;

const int N_MAX = 150010;
ll parent[N_MAX];
vector<vector<ll> > G;
ll N;

ll findRoot(ll a){
    if(a==parent[a]){
        return a;
    }
    else{
        return parent[a] = findRoot(parent[a]);
    }
}

void printGroup(){
    br();
    FOR(i, 1, N+1){
        cout << "i=" << i << " ";
        vprint(G[i]);
    }
}

void unite(ll a, ll b){
    if(findRoot(a)==findRoot(b)){
        return;
    }

    // aの方が大きいグループとする
    if(G[a].size() < G[b].size()){
        swap(a, b);
    }

    ll rootA = findRoot(a);
    ll rootB = findRoot(b);
    parent[rootB] = rootA;

    for(ll member : G[rootB]){
        G[rootA].push_back(member);
    }
    G[b].clear();
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);

    // input
    cin >> N;
    G.resize(N+1);

    FOR(i, 1, N+1){
        parent[i] = i;
        G[i].push_back(i);
    }

    FOR(i, 0, N){
        ll x, y;
        cin >> x >> y;

        unite(x, y);
        //printGroup();
    }

    ll a = findRoot(1);
    cout << G[a][0];
    ll L = G[a].size();
    FOR(i, 1, L){
        cout << " " << G[a][i];
    }
    cout << endl;

    return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define fi first
#define si second
#define ld long double
#define pb push_back
using namespace std;
const ll inf = 1e18;
const ll maxn = 200000;
ll n, m, x, y;
ll p[maxn];
ll siz[maxn];
vector<ll> ans[maxn];
ll get_r(ll x) {
     // cout << x <<endl;
      if (p[x] == x)
            return x;
      else return p[x] = get_r(p[x]);
}
void union_r(ll x, ll y) {
     // cout << x <<" "<< y <<endl;
      if (siz[x] > siz[y]) {
            swap(x, y);
      }
      for (auto p1 : ans[y]) {
            ans[x].pb(p1);
      }
      p[y] = x;
}
int main() {
   // freopen("cowdate.in", "r", stdin);
    // freopen("cowdate.out", "w", stdout);
     ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
     cin >> n;
     for (ll i = 1; i <= n; ++i) {
            ans[i].pb(i);
            siz[i] = 1;
            p[i] = i;
     }
      for (ll i = 1; i <= n - 1; ++i) {
            ll x, y;
            cin >> x >> y;
            x = get_r(x);
            y = get_r(y);
            union_r(x, y);
      }
      for (auto p : ans[get_r(1)])
            cout << p <<" ";
      cout << endl;
}


#include <bits/stdc++.h>
#define ll int
#define fi first
#define si second
#define ld long double
#define pb push_back
using namespace std;
const ll inf = 1e18;
const ll maxn = 160000;
ll n, m, x, y;
ll p[maxn];
vector<ll> ans[maxn];
ll get_r(ll x) {
     // cout << x <<endl;
      if (p[x] == x)
            return x;
      else return p[x] = get_r(p[x]);
}
void union_r(ll x, ll y) {
     // cout << x <<" "<< y <<endl;
      if (rand() & 1) {
            swap(x, y);
      }
      for (auto p1 : ans[y]) {
            ans[x].pb(p1);
      }
      p[y] = x;
}
int main() {
   // freopen("cowdate.in", "r", stdin);
    // freopen("cowdate.out", "w", stdout);
     ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
     cin >> n;
     for (ll i = 1; i <= n; ++i) {
            ans[i].pb(i);
            siz[i] = 1;
            p[i] = i;
     }
      for (ll i = 1; i <= n - 1; ++i) {
            ll x, y;
            cin >> x >> y;
            x = get_r(x);
            y = get_r(y);
            union_r(x, y);
      }
      for (auto p : ans[get_r(1)])
            cout << p <<" ";
      cout << endl;
}


#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
#define ll int
#define fi first
#define si second
#define ld long double
#define pb push_back
using namespace std;
const ll inf = 1e9;
const ll maxn = 160000;
ll n, m, x, y;
ll p[maxn];
vector<ll> ans[maxn];
ll get_r(ll x) {
     // cout << x <<endl;
      if (p[x] == x)
            return x;
      else return p[x] = get_r(p[x]);
}
void union_r(ll x, ll y) {
     // cout << x <<" "<< y <<endl;
      x = get_r(x);
      y = get_r(y);
      if (ans[y].size() > ans[x].size()) {
            swap(x, y);
      }
      for (int p1 : ans[y]) {
            ans[x].pb(p1);
      }
      p[y] = x;
}
int main() {
   // freopen("cowdate.in", "r", stdin);
    // freopen("cowdate.out", "w", stdout);
     ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
     cin >> n;
     for (ll i = 1; i <= n; ++i) {
            ans[i].pb(i);
            p[i] = i;
     }
      for (ll i = 1; i <= n - 1; ++i) {
            ll x, y;
            cin >> x >> y;
            x = get_r(x);
            y = get_r(y);
            union_r(x, y);
      }
      for (int p1 : ans[get_r(1)])
            cout << p1 <<" ";
      return 0;
}


#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
#define ll int
#define fi first
#define si second
#define ld long double
#define pb push_back
using namespace std;
const ll inf = 1e9;
const ll maxn = 160000;
ll n, m, x, y;
ll p[maxn];
vector<ll> ans[maxn];
ll get_r(ll x) {
     // cout << x <<endl;
      if (p[x] == x)
            return x;
      else return p[x] = get_r(p[x]);
}
void union_r(ll x, ll y) {
     // cout << x <<" "<< y <<endl;
      if (ans[x].size() > ans[y].size()) {
            swap(x, y);
      }
      for (auto p1 : ans[y]) {
            ans[x].pb(p1);
      }
      p[y] = x;
}
int main() {
   // freopen("cowdate.in", "r", stdin);
    // freopen("cowdate.out", "w", stdout);
     ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
     cin >> n;
     for (ll i = 1; i <= n; ++i) {
            ans[i].pb(i);
            p[i] = i;
     }
      for (ll i = 1; i <= n - 1; ++i) {
            ll x, y;
            cin >> x >> y;
            x = get_r(x);
            y = get_r(y);
            union_r(x, y);
      }
      for (auto p : ans[get_r(1)])
            cout << p <<" ";
      return 0;
}


#include <bits/stdc++.h>
#define ll int
#define fi first
#define si second
#define ld long double
#define pb push_back
using namespace std;
const ll inf = 1e9;
const ll maxn = 160000;
ll n, m, x, y;
ll p[maxn];
vector<ll> ans[maxn];
ll get_r(ll x) {
     // cout << x <<endl;
      if (p[x] == x)
            return x;
      else return p[x] = get_r(p[x]);
}
void union_r(ll x, ll y) {
     // cout << x <<" "<< y <<endl;
      if (rand() & 1) {
            swap(x, y);
      }
      for (auto p1 : ans[y]) {
            ans[x].pb(p1);
      }
      p[y] = x;
}
int main() {
   // freopen("cowdate.in", "r", stdin);
    // freopen("cowdate.out", "w", stdout);
    srand(time(0));
     ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
     cin >> n;
     for (ll i = 1; i <= n; ++i) {
            ans[i].pb(i);
            p[i] = i;
     }
      for (ll i = 1; i <= n - 1; ++i) {
            ll x, y;
            cin >> x >> y;
            x = get_r(x);
            y = get_r(y);
            union_r(x, y);
      }
      for (auto p : ans[get_r(1)])
            cout << p <<" ";
      cout << endl;
}


#include <bits/stdc++.h>
#define ll int
#define fi first
#define si second
#define ld long double
#define pb push_back
using namespace std;
const ll inf = 1e18;
const ll maxn = 200000;
ll n, m, x, y;
ll p[maxn];
ll siz[maxn];
vector<ll> ans[maxn];
ll get_r(ll x) {
     // cout << x <<endl;
      if (p[x] == x)
            return x;
      else return p[x] = get_r(p[x]);
}
void union_r(ll x, ll y) {
     // cout << x <<" "<< y <<endl;
      //if (siz[x] > siz[y]) {
        //    swap(x, y);
      //}
      for (auto p1 : ans[y]) {
            ans[x].pb(p1);
      }
      ans[y].clear();
      p[y] = x;
}
int main() {
   // freopen("cowdate.in", "r", stdin);
    // freopen("cowdate.out", "w", stdout);
     ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
     cin >> n;
     for (ll i = 1; i <= n; ++i) {
            ans[i].pb(i);
            siz[i] = 1;
            p[i] = i;
     }
      for (ll i = 1; i <= n - 1; ++i) {
            ll x, y;
            cin >> x >> y;
            x = get_r(x);
            y = get_r(y);
            union_r(x, y);
      }
      for (auto p : ans[get_r(1)])
            cout << p <<" ";
      cout << endl;
}


#include <bits/stdc++.h>
#define ll int
#define fi first
#define si second
#define ld long double
#define pb push_back
using namespace std;
const ll inf = 1e18;
const ll maxn = 160000;
ll n, m, x, y;
ll p[maxn];
ll siz[maxn];
vector<ll> ans[maxn];
ll get_r(ll x) {
     // cout << x <<endl;
      if (p[x] == x)
            return x;
      else return p[x] = get_r(p[x]);
}
void union_r(ll x, ll y) {
     // cout << x <<" "<< y <<endl;
      if (ans[x].size() > ans[y].size()) {
            swap(x, y);
      }
      for (auto p1 : ans[y]) {
            ans[x].pb(p1);
      }
      p[y] = x;
}
int main() {
   // freopen("cowdate.in", "r", stdin);
    // freopen("cowdate.out", "w", stdout);
     ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
     cin >> n;
     for (ll i = 1; i <= n; ++i) {
            ans[i].pb(i);
            siz[i] = 1;
            p[i] = i;
     }
      for (ll i = 1; i <= n - 1; ++i) {
            ll x, y;
            cin >> x >> y;
            x = get_r(x);
            y = get_r(y);
            union_r(x, y);
      }
      for (auto p : ans[get_r(1)])
            cout << p <<" ";
      cout << endl;
}


#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
#define ll int
#define fi first
#define si second
#define ld long double
#define pb push_back
using namespace std;
const ll inf = 1e9;
const ll maxn = 160000;
ll n, m, x, y;
ll p[maxn];
ll l[maxn];
ll r[maxn];
ll siz[maxn];
ll nxt[maxn];
vector<ll> ans[maxn];
bool us[maxn];
ll get_r(ll x) {
     // cout << x <<endl;
      if (p[x] == x)
            return x;
      else return p[x] = get_r(p[x]);
}
void union_r(ll x, ll y) {
     // cout << x <<" "<< y <<endl;
      x = get_r(x);
      y = get_r(y);
      if (siz[y] > siz[x]) {
            swap(x, y);
      }
    //  for (int p1 : ans[y]) {
      //      ans[x].pb(p1);
      //}
      nxt[l[x]] = r[y];
      l[x] = l[y];
      p[y] = x;
      siz[x] += siz[y];
      us[r[y]] = 1;
}
int main() {
   // freopen("cowdate.in", "r", stdin);
    // freopen("cowdate.out", "w", stdout);
     ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
     cin >> n;
     for (ll i = 1; i <= n; ++i) {
            ans[i].pb(i);
            p[i] = i;
            l[i] = r[i] = i;
     }
      for (ll i = 1; i <= n - 1; ++i) {
            ll x, y;
            cin >> x >> y;
            x = get_r(x);
            y = get_r(y);
            union_r(x, y);
      }
      ll x = 1;
      for (ll i = 1; i <= n; ++i)
            if (!us[i])
                  x = i;
      for (ll i = 1; i <= n; ++i) {
            cout << x <<" ";
            x = nxt[x];
      }
      return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define fi first
#define si second
#define ld long double
#define pb push_back
using namespace std;
const ll inf = 1e18;
const ll maxn = 2000000;
ll n, m, x, y;
ll p[maxn];
ll siz[maxn];
vector<ll> ans[maxn];
ll get_r(ll x) {
     // cout << x <<endl;
      if (p[x] == x)
            return x;
      else return p[x] = get_r(p[x]);
}
void union_r(ll x, ll y) {
     // cout << x <<" "<< y <<endl;
      if (siz[x] > siz[y]) {
            swap(x, y);
      }
      for (auto p1 : ans[y]) {
            ans[x].pb(p1);
      }
      p[y] = x;
}
int main() {
   // freopen("cowdate.in", "r", stdin);
    // freopen("cowdate.out", "w", stdout);
     ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
     cin >> n;
     for (ll i = 1; i <= n; ++i) {
            ans[i].pb(i);
            siz[i] = 1;
            p[i] = i;
     }
      for (ll i = 1; i <= n - 1; ++i) {
            ll x, y;
            cin >> x >> y;
            x = get_r(x);
            y = get_r(y);
            union_r(x, y);
      }
      for (auto p : ans[get_r(1)])
            cout << p <<" ";
      cout << endl;
}


#include <bits/stdc++.h>
#define ll long long
#define fi first
#define si second
#define ld long double
#define pb push_back
using namespace std;
const ll inf = 1e18;
const ll maxn = 200000;
ll n, m, x, y;
ll p[maxn];
ll siz[maxn];
vector<ll> ans[maxn];
ll get_r(ll x) {
     // cout << x <<endl;
      if (p[x] == x)
            return x;
      else return p[x] = get_r(p[x]);
}
void union_r(ll x, ll y) {
     // cout << x <<" "<< y <<endl;
      if (siz[x] > siz[y]) {
            swap(x, y);
      }
      for (auto p1 : ans[y]) {
            ans[x].pb(p1);
      }
      ans[y].clear();
      p[y] = x;
}
int main() {
   // freopen("cowdate.in", "r", stdin);
    // freopen("cowdate.out", "w", stdout);
     ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
     cin >> n;
     for (ll i = 1; i <= n; ++i) {
            ans[i].pb(i);
            siz[i] = 1;
            p[i] = i;
     }
      for (ll i = 1; i <= n - 1; ++i) {
            ll x, y;
            cin >> x >> y;
            x = get_r(x);
            y = get_r(y);
            union_r(x, y);
      }
      for (auto p : ans[get_r(1)])
            cout << p <<" ";
      cout << endl;
}


#include <bits/stdc++.h>
#define ll int
#define fi first
#define si second
#define ld long double
#define pb push_back
using namespace std;
const ll inf = 1e18;
const ll maxn = 200000;
ll n, m, x, y;
ll p[maxn];
ll siz[maxn];
vector<ll> ans[maxn];
ll get_r(ll x) {
     // cout << x <<endl;
      if (p[x] == x)
            return x;
      else return p[x] = get_r(p[x]);
}
void union_r(ll x, ll y) {
     // cout << x <<" "<< y <<endl;
      if (siz[x] > siz[y]) {
            swap(x, y);
      }
      for (auto p1 : ans[y]) {
            ans[x].pb(p1);
      }
      ans[y].clear();
      p[y] = x;
}
int main() {
   // freopen("cowdate.in", "r", stdin);
    // freopen("cowdate.out", "w", stdout);
     ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
     cin >> n;
     for (ll i = 1; i <= n; ++i) {
            ans[i].pb(i);
            siz[i] = 1;
            p[i] = i;
     }
      for (ll i = 1; i <= n - 1; ++i) {
            ll x, y;
            cin >> x >> y;
            x = get_r(x);
            y = get_r(y);
            union_r(x, y);
      }
      for (auto p : ans[get_r(1)])
            cout << p <<" ";
      cout << endl;
}


#include <bits/stdc++.h>
//CLOCKS_PER_SEC
#define se second
#define fi first
#define ll long long
#define Pii pair<int,int>
#define Pli pair<ll,int>
#define ull unsigned long long
#define pb push_back
#define fio ios::sync_with_stdio(false);cin.tie(0);
const double Pi=3.14159265;
const int N=3e5+10;
const ull base=163;
const int INF=0x3f3f3f3f;
const int mod=(int)1e9+7;
using namespace std;
int n,m;
int a[N];
int fa[N];
int tot=0;
int findfa(int x){return fa[x]==x?x:fa[x]=findfa(fa[x]);}
int indeg[N];
vector<int>E[N];
bool vis[N];
int nx[N];
void merge(int x,int y){
    int X=findfa(x),Y=findfa(y);
    nx[x]=Y;
    fa[Y]=x;
    indeg[Y]++;
}
vector<int>ans;
void dfs(int x){
   // cout<<x<<endl;
    if(x==0)return ;
    ans.pb(x);
    dfs(nx[x]);
}
int main(){
    scanf("%d",&n);
    for(int i=1;i<=n;++i)fa[i]=i;
    for(int i=1;i<n;++i){
        int x,y;scanf("%d%d",&x,&y);
        merge(x,y);
    }
 //   for(int i=1;i<=n;++i)cout<<indeg[i]<<endl;
    for(int i=1;i<=n;++i){
        if(indeg[i]==0){
            dfs(i);
            break;
        }
    }
    for(auto x:ans)cout<<x<<" ";
    return 0;
}
/*
5
1 4
2 5
3 1
4 5
3 1 4 2 5

*/


#include <bits/stdc++.h>
//CLOCKS_PER_SEC
#define se second
#define fi first
#define ll long long
#define Pii pair<int,int>
#define Pli pair<ll,int>
#define ull unsigned long long
#define pb push_back
#define fio ios::sync_with_stdio(false);cin.tie(0);
const double Pi=3.14159265;
const int N=3e5+10;
const ull base=163;
const int INF=0x3f3f3f3f;
const int mod=(int)1e9+7;
using namespace std;
int n,m;
int a[N];
int fa[N];
int findfa(int x){return fa[x]==x?x:findfa(fa[x]);}
int indeg[N];
vector<int>E[N];
void merge(int x,int y){
    int X=findfa(x),Y=findfa(y);
    E[x].pb(Y);
    fa[Y]=X;
    indeg[Y]++;
}
int main(){
    scanf("%d",&n);
    int now=3e5;
    for(int i=1;i<=n;++i)fa[i]=i;
    for(int i=1;i<n;++i){
        int x,y;scanf("%d%d",&x,&y);
        merge(x,y);
    }
    queue<int>q;
    for(int i=1;i<=n;++i){
        if(!indeg[i])q.push(i);
    }
    assert(q.size()==1);
    vector<int>vec;
    while(!q.empty()){
        int u=q.front();q.pop();
        vec.pb(u);
        for(auto v:E[u]){
            indeg[v]--;
            if(indeg[v]==0)q.push(v);
        }
    }
    for(auto a:vec){
        cout<<a<<" ";
    }
    return 0;
}
/*
5
1 4
2 5
3 1
4 5
3 1 4 2 5

*/


#include <bits/stdc++.h>
//CLOCKS_PER_SEC
#define se second
#define fi first
#define ll long long
#define Pii pair<int,int>
#define Pli pair<ll,int>
#define ull unsigned long long
#define pb push_back
#define fio ios::sync_with_stdio(false);cin.tie(0);
const double Pi=3.14159265;
const int N=3e5+10;
const ull base=163;
const int INF=0x3f3f3f3f;
const int mod=(int)1e9+7;
using namespace std;
int n,m;
int a[N];
int fa[N];
int tot=0;
int findfa(int x){return fa[x]==x?x:fa[x]=findfa(fa[x]);}
int indeg[N];
vector<int>E[N];
bool vis[N];
void merge(int x,int y){
    int X=findfa(x),Y=findfa(y);
    E[x].pb(Y);
    fa[Y]=X;
    indeg[Y]++;
}
int main(){
    scanf("%d",&n);
    int now=3e5;
    for(int i=1;i<=n;++i)fa[i]=i;
    for(int i=1;i<n;++i){
        int x,y;scanf("%d%d",&x,&y);
        merge(x,y);
    }
    queue<int>q;
    for(int i=1;i<=n;++i){
        if(!indeg[i])q.push(i);
    }
    vector<int>vec;
    while(!q.empty()){
        int u=q.front();q.pop();
        vec.pb(u);
        for(auto v:E[u]){
            indeg[v]--;
            if(indeg[v]==0)q.push(v);
        }
    }
    for(auto a:vec){
        printf("%d ",a);
    }
    return 0;
}
/*
5
1 4
2 5
3 1
4 5
3 1 4 2 5

*/


#include <bits/stdc++.h>
//CLOCKS_PER_SEC
#define se second
#define fi first
#define ll long long
#define Pii pair<int,int>
#define Pli pair<ll,int>
#define ull unsigned long long
#define pb push_back
#define fio ios::sync_with_stdio(false);cin.tie(0);
const double Pi=3.14159265;
const int N=3e5+10;
const ull base=163;
const int INF=0x3f3f3f3f;
const int mod=(int)1e9+7;
using namespace std;
int n,m;
int a[N];
int fa[N];
int tot=0;
int findfa(int x){return fa[x]==x?x:fa[x]=findfa(fa[x]);}
int indeg[N];
vector<int>E[N];
bool vis[N];
void merge(int x,int y){
    int X=findfa(x),Y=findfa(y);
    E[x].pb(Y);
    fa[Y]=x;
    indeg[Y]++;
}
int main(){
    scanf("%d",&n);
    for(int i=1;i<=n;++i)fa[i]=i;
    for(int i=1;i<n;++i){
        int x,y;scanf("%d%d",&x,&y);
        merge(x,y);
    }
    queue<int>q;
    for(int i=1;i<=n;++i){
        if(!indeg[i])q.push(i);
    }
    vector<int>vec;
    while(!q.empty()){
        int u=q.front();q.pop();
        vec.pb(u);
        for(auto v:E[u]){
            indeg[v]--;
            if(indeg[v]==0)q.push(v);
        }
    }
    for(auto a:vec){
        printf("%d ",a);
    }
    return 0;
}
/*
5
1 4
2 5
3 1
4 5
3 1 4 2 5

*/


#include <bits/stdc++.h>
//CLOCKS_PER_SEC
#define se second
#define fi first
#define ll long long
#define Pii pair<int,int>
#define Pli pair<ll,int>
#define ull unsigned long long
#define pb push_back
#define fio ios::sync_with_stdio(false);cin.tie(0);
const double Pi=3.14159265;
const int N=3e5+10;
const ull base=163;
const int INF=0x3f3f3f3f;
const int mod=(int)1e9+7;
using namespace std;
int n,m;
int a[N];
int fa[N];
int tot=0;
int findfa(int x){return fa[x]==x?x:findfa(fa[x]);}
int indeg[N];
vector<int>E[N];
bool vis[N];
void merge(int x,int y){
    int X=findfa(x),Y=findfa(y);
    E[x].pb(Y);
    fa[Y]=X;
    indeg[Y]++;
}
int main(){
    scanf("%d",&n);
    int now=3e5;
    for(int i=1;i<=n;++i)fa[i]=i;
    for(int i=1;i<n;++i){
        int x,y;scanf("%d%d",&x,&y);
        merge(x,y);
    }
    queue<int>q;
    for(int i=1;i<=n;++i){
        if(!indeg[i])q.push(i);
    }
    vector<int>vec;
    while(!q.empty()){
        int u=q.front();q.pop();
        if(vis[u])continue;
        vec.pb(u);
        vis[u]=1;
        for(auto v:E[u]){
            indeg[v]--;
            if(indeg[v]==0)q.push(v);
        }
    }
    for(auto a:vec){
        cout<<a<<" ";
    }
    return 0;
}
/*
5
1 4
2 5
3 1
4 5
3 1 4 2 5

*/


#include <bits/stdc++.h>
//CLOCKS_PER_SEC
#define se second
#define fi first
#define ll long long
#define Pii pair<int,int>
#define Pli pair<ll,int>
#define ull unsigned long long
#define pb push_back
#define fio ios::sync_with_stdio(false);cin.tie(0);
const double Pi=3.14159265;
const int N=3e5+10;
const ull base=163;
const int INF=0x3f3f3f3f;
const int mod=(int)1e9+7;
using namespace std;
int n,m;
int a[N];
int fa[N];
int tot=0;
int findfa(int x){
    tot++;
    if(tot>=2e7){
        cout<<"check\n",0;
        tot=0;
    }
    return fa[x]==x?x:findfa(fa[x]);}
int indeg[N];
vector<int>E[N];
void merge(int x,int y){
    int X=findfa(x),Y=findfa(y);
    E[x].pb(Y);
    fa[Y]=X;
    indeg[Y]++;
}
int main(){
    scanf("%d",&n);
    int now=3e5;
    for(int i=1;i<=n;++i)fa[i]=i;
    for(int i=1;i<n;++i){
        int x,y;scanf("%d%d",&x,&y);
        merge(x,y);
    }
    queue<int>q;
    for(int i=1;i<=n;++i){
        if(!indeg[i])q.push(i);
    }
    vector<int>vec;
    while(!q.empty()){
        int u=q.front();q.pop();
        vec.pb(u);
        for(auto v:E[u]){
            indeg[v]--;
            if(indeg[v]==0)q.push(v);
        }
    }
    for(auto a:vec){
        cout<<a<<" ";
    }
    return 0;
}
/*
5
1 4
2 5
3 1
4 5
3 1 4 2 5

*/


#include <bits/stdc++.h>
//CLOCKS_PER_SEC
#define se second
#define fi first
#define ll long long
#define Pii pair<int,int>
#define Pli pair<ll,int>
#define ull unsigned long long
#define pb push_back
#define fio ios::sync_with_stdio(false);cin.tie(0);
const double Pi=3.14159265;
const int N=3e5+10;
const ull base=163;
const int INF=0x3f3f3f3f;
const int mod=(int)1e9+7;
using namespace std;
int n,m;
int a[N];
int fa[N];
int tot=0;
int findfa(int x){return fa[x]==x?x:fa[x]=findfa(fa[x]);}
vector<int>E[N];
bool vis[N];
int nx[N];
void merge(int x,int y){
    int X=findfa(x),Y=findfa(y);E[X].pb(Y);
    fa[Y]=X;
}
vector<int>ans;
void dfs(int x){
    if(x==0)return ;
    ans.pb(x);
    for(int i=0;i<E[x].size();++i){
        int v=E[x][i];
        dfs(v);
    }
}
int main(){
    scanf("%d",&n);
    for(int i=1;i<=n;++i)fa[i]=i;
    for(int i=1;i<n;++i){
        int x,y;scanf("%d%d",&x,&y);
        merge(x,y);
    }
    for(int i=1;i<=n;++i){
        if(fa[i]==i){
            dfs(i);
            break;
        }
    }
    for(auto x:ans)cout<<x<<" ";
    return 0;
}
/*
5
1 4
2 5
3 1
4 5
3 1 4 2 5

*/


#include <bits/stdc++.h>
//CLOCKS_PER_SEC
#define se second
#define fi first
#define ll long long
#define Pii pair<int,int>
#define Pli pair<ll,int>
#define ull unsigned long long
#define pb push_back
#define fio ios::sync_with_stdio(false);cin.tie(0);
const double Pi=3.14159265;
const int N=3e5+10;
const ull base=163;
const int INF=0x3f3f3f3f;
const int mod=(int)1e9+7;
using namespace std;
int n,m;
int a[N];
int fa[N];
int tot=0;
int findfa(int x){return fa[x]==x?x:fa[x]=findfa(fa[x]);}
vector<int>E[N];
bool vis[N];
int nx[N];
void merge(int x,int y){
    int X=findfa(x),Y=findfa(y);
    nx[x]=Y;
    fa[Y]=X;
}
vector<int>ans;
void dfs(int x){
    if(x==0)return ;
    ans.pb(x);
    dfs(nx[x]);
}
int main(){
    scanf("%d",&n);
    for(int i=1;i<=n;++i)fa[i]=i;
    for(int i=1;i<n;++i){
        int x,y;scanf("%d%d",&x,&y);
        merge(x,y);
    }
    for(int i=1;i<=n;++i){
        if(fa[i]==i){
            dfs(i);
            break;
        }
    }
    for(auto x:ans)cout<<x<<" ";
    return 0;
}
/*
5
1 4
2 5
3 1
4 5
3 1 4 2 5

*/


#include <bits/stdc++.h>
//CLOCKS_PER_SEC
#define se second
#define fi first
#define ll long long
#define Pii pair<int,int>
#define Pli pair<ll,int>
#define ull unsigned long long
#define pb push_back
#define fio ios::sync_with_stdio(false);cin.tie(0);
const double Pi=3.14159265;
const int N=3e5+10;
const ull base=163;
const int INF=0x3f3f3f3f;
const int mod=(int)1e9+7;
using namespace std;
int n,m;
int a[N];
int fa[N];
int findfa(int x){return fa[x]==x?x:findfa(fa[x]);}
int indeg[N];
vector<int>E[N];
void merge(int x,int y){
    int X=findfa(x),Y=findfa(y);
    E[x].pb(Y);
    fa[Y]=X;
    indeg[Y]++;
}
int main(){
    scanf("%d",&n);
    int now=3e5;
    for(int i=1;i<=n;++i)fa[i]=i;
    for(int i=1;i<n;++i){
        int x,y;scanf("%d%d",&x,&y);
        merge(x,y);
    }
    queue<int>q;
    for(int i=1;i<=n;++i){
        if(!indeg[i])q.push(i);
    }
    vector<int>vec;
    while(!q.empty()){
        int u=q.front();q.pop();
        vec.pb(u);
        for(auto v:E[u]){
            indeg[v]--;
            if(indeg[v]==0)q.push(v);
        }
    }
    for(auto a:vec){
        cout<<a<<" ";
    }
    return 0;
}
/*
5
1 4
2 5
3 1
4 5
3 1 4 2 5

*/


    #include <bits/stdc++.h>
    using namespace std;

    #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    #define endl "\n"
    #define ll long long

    const int mxN=1.5e5;
    int n, p[mxN];
    vector<int> v[mxN];

    int find(int x) {
    	return x==p[x]?x:(p[x]=find(p[x]));
    }

    int32_t main()
    {
    	IOS;
    	cin >> n;
    	iota(p, p+n, 0);
    	for(int i=0; i<n; ++i)
    		v[i]={i};
    	for(int i=1; i<n; ++i) {
    		int x, y;
    		cin >> x >> y, --x, --y;
    		x=find(x), y=find(y);
    		if(v[x].size()>v[y].size())
    			swap(x, y);
    		p[x]=y;
    		v[y].insert(v[y].end(), v[x].begin(), v[x].end());
    	}
    	for(int vi : v[find(0)])
    		cout << vi+1 << " ";
    	return 0;
    }


#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>

using namespace std;
using ll = long long;
const int mxN = 150001;
int gt[mxN];
vector<int> lst[mxN];
int find(int a) {
    return gt[a]==a ? a : find(gt[a]);
}
int merge(int a, int b) {
    a = find(a);
    b = find(b);
    if(lst[b].size()>lst[a].size()) swap(a, b);
    gt[b] = a;
    lst[a].insert(lst[a].end(), lst[b].begin(), lst[b].end());
}
int n;
int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin>>n;
    for(int i=0; i<n; ++i) {
        gt[i] = i;
        lst[i].push_back(i);
    }
    int a,b;
    for(int i=0; i<n-1; ++i) {
        cin>>a>>b;
        a--; b--;
        merge(a, b);
        /*for(int j=0; j<n; ++j) {
            for(int k: lst[j]) {
                cout<<k<<" ";
            }
            cout<<"\n";
        }
        cout<<"\n";*/
    }
    int k = find(0);
    for(int i : lst[k]) {
        cout<<(i+1)<<" ";
    }
    return 0;
}


#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>

using namespace std;
using ll = long long;
const int mxN = 150001;
int gt[mxN];
int sz[mxN];
vector<int> lst[mxN];
int find(int a) {
    return gt[a]==a ? a : find(gt[a]);
}
int merge(int a, int b) {
    int a = find(a);
    int b = find(b);
    if(lst[b].size()>lst[a].size()) swap(a, b);
    gt[b] = a;
    lst[a1].insert(lst[a1].end(), lst[b1].begin(), lst[b1].end());
}
int n;
int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin>>n;
    for(int i=0; i<n; ++i) {
        gt[i] = i;
        sz[i] = 0;
        lst[i].push_back(i);
    }
    int a,b;
    for(int i=0; i<n-1; ++i) {
        cin>>a>>b;
        a--; b--;
        merge(a, b);
        /*for(int j=0; j<n; ++j) {
            for(int k: lst[j]) {
                cout<<k<<" ";
            }
            cout<<"\n";
        }
        cout<<"\n";*/
    }
    int k = find(0);
    for(int i : lst[k]) {
        cout<<(i+1)<<" ";
    }
    return 0;
}


#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>

using namespace std;
using ll = long long;
const int mxN = 150001;
int gt[mxN];
int sz[mxN];
vector<int> lst[mxN];
int find(int a) {
    return gt[a]==a ? a : find(gt[a]);
}
int merge(int a, int b) {
    int a1 = find(a);
    int b1 = find(b);
    if(b1>a1) swap(a1, b1);
    gt[a] = a1;
    gt[b] = a1;
    gt[b1] = a1;
    sz[a1]+=sz[b1];
    lst[a1].insert(lst[a1].end(), lst[b1].begin(), lst[b1].end());
    lst[b1].clear();
}
int n;
int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin>>n;
    for(int i=0; i<n; ++i) {
        gt[i] = i;
        sz[i] = 0;
        lst[i].push_back(i);
    }
    int a,b;
    for(int i=0; i<n-1; ++i) {
        cin>>a>>b;
        a--; b--;
        merge(a, b);
        /*for(int j=0; j<n; ++j) {
            for(int k: lst[j]) {
                cout<<k<<" ";
            }
            cout<<"\n";
        }
        cout<<"\n";*/
    }
    int k = find(0);
    for(int i : lst[k]) {
        cout<<(i+1)<<" ";
    }
    return 0;
}


#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>

using namespace std;
using ll = long long;
const int mxN = 150001;
int gt[mxN];
int sz[mxN];
vector<int> lst[mxN];
int find(int a) {
    return gt[a]==a ? a : find(gt[a]);
}
int merge(int a, int b) {
    int a1 = find(a);
    int b1 = find(b);
    if(b1>a1) swap(a1, b1);
    gt[a] = a1;
    gt[b] = a1;
    gt[b1] = a1;
    sz[a1]+=sz[b1];
    for(int i: lst[b1]) {
        lst[a1].push_back(i);
    }
    lst[b1].clear();
}
int n;
int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin>>n;
    for(int i=0; i<n; ++i) {
        gt[i] = i;
        sz[i] = 0;
        lst[i].push_back(i);
    }
    int a,b;
    for(int i=0; i<n-1; ++i) {
        cin>>a>>b;
        a--; b--;
        merge(a, b);
    }
    int k = find(0);
    for(int i : lst[k]) {
        cout<<(i+1)<<" ";
    }
    return 0;
}


#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>

using namespace std;
using ll = long long;
const int mxN = 150001;
int gt[mxN];
int sz[mxN];
vector<int> lst[mxN];
int find(int a) {
    return gt[a]==a ? a : find(gt[a]);
}
int merge(int a, int b) {
    int a1 = find(a);
    int b1 = find(b);
    if(b1>a1) swap(a1, b1);
    gt[a] = a1;
    gt[b] = a1;
    gt[b1] = a1;
    sz[a1]+=sz[b1];
    lst[a1].insert(lst[a1].end(), lst[b1].begin(), lst[b2].end());
    lst[b1].clear();
}
int n;
int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin>>n;
    for(int i=0; i<n; ++i) {
        gt[i] = i;
        sz[i] = 0;
        lst[i].push_back(i);
    }
    int a,b;
    for(int i=0; i<n-1; ++i) {
        cin>>a>>b;
        a--; b--;
        merge(a, b);
        /*for(int j=0; j<n; ++j) {
            for(int k: lst[j]) {
                cout<<k<<" ";
            }
            cout<<"\n";
        }
        cout<<"\n";*/
    }
    int k = find(0);
    for(int i : lst[k]) {
        cout<<(i+1)<<" ";
    }
    return 0;
}


#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>

using namespace std;
using ll = long long;
const int mxN = 150001;
int gt[mxN];
int sz[mxN];
vector<int> lst[mxN];
int find(int a) {
    return gt[a]==a ? a : find(gt[a]);
}
int merge(int a, int b) {
    int a1 = find(a);
    int b1 = find(b);
    if(b1>a1) swap(a1, b1);
    gt[a] = a1;
    gt[b] = a1;
    gt[b1] = a1;
    sz[a1]+=sz[b1];
    for(int i: lst[b1]) {
        lst[a1].push_back(i);
    }
    lst[b1].clear();
    lst[a].clear();
    lst[b].clear();
}
int n;
int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin>>n;
    for(int i=0; i<n; ++i) {
        gt[i] = i;
        sz[i] = 0;
        lst[i].push_back(i);
    }
    int a,b;
    for(int i=0; i<n-1; ++i) {
        cin>>a>>b;
        a--; b--;
        merge(a, b);
    }
    int k = find(0);
    for(int i : lst[k]) {
        cout<<(i+1)<<" ";
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
// #define int long long int
#define endl "\n"
#define F first
#define S second
#define mod 1000000007
int root[200005];
int sz[150005];
vector<int> v[150005];

int fndroot(int x){
    while(x != root[x]){
        x = root[root[x]];
    }
    return x;
}

void combine(int x,int y){
    int xrt = fndroot(x);
    int yrt = fndroot(y);
    if(xrt == yrt) return;
    if(sz[xrt]<sz[yrt]){
        root[xrt] = root[yrt];
        for(int i=0;i<v[xrt].size();i++){
            v[yrt].push_back(v[xrt][i]);
        }
        v[xrt].clear();
    }else{
        root[yrt] = root[xrt];
        for(int i=0;i<v[yrt].size();i++){
            v[xrt].push_back(v[yrt][i]);
        }
        v[yrt].clear();
    }
    return;
}

void solve(){
    int n;
    cin>>n;
    for(int i=1;i<=n;i++){
        root[i] = i;
        sz[i] = 1;
        v[i].push_back(i);
    }
    for(int i=0;i<n-1;i++){
        int x,y;
        cin>>x>>y;
        combine(x,y);
        // for(int i=1;i<=n;i++){
        //     cout<<root[i]<<" ";
        // }
        // cout<<endl;
        // for(int i=1;i<=n;i++){
        //     cout<<lst[i]<<" ";
        // }
        // cout<<endl;
    }
    for(int i=1;i<=n;i++){
        if(!v[i].empty()){
            for(int j=0;j<v[i].size();j++){
                cout<<v[i][j]<<" ";
            }
        }
    }
    return;
}

int32_t main(){
    int t=1;
    // scanf("%intd",&t);
    for(int i=0;i<t;i++){
        solve();
    }
    cerr <<endl<< "Time elapsed : " << clock() * 1000.0 / CLOCKS_PER_SEC << " ms" << '\n';
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
// #define int long long int
#define endl "\n"
#define F first
#define S second
#define mod 1000000007
int root[150005];
int sz[150005];
vector<int> v[150005];

int fndroot(int x){
    while(x != root[x]){
        x = root[root[x]];
    }
    return x;
}

void combine(int x,int y){
    int xrt = fndroot(x);
    int yrt = fndroot(y);
    if(xrt == yrt) return;
    if(sz[xrt]<sz[yrt]){
        root[xrt] = root[yrt];
        for(int i=0;i<v[xrt].size();i++){
            v[yrt].push_back(v[xrt][i]);
        }
        v[xrt].clear();
    }else{
        root[yrt] = root[xrt];
        for(int i=0;i<v[yrt].size();i++){
            v[xrt].push_back(v[yrt][i]);
        }
        v[yrt].clear();
    }
    return;
}

void solve(){
    int n;
    cin>>n;
    for(int i=1;i<=n;i++){
        root[i] = i;
        sz[i] = 1;
        v[i].push_back(i);
    }
    for(int i=0;i<n-1;i++){
        int x,y;
        cin>>x>>y;
        combine(x,y);
        // for(int i=1;i<=n;i++){
        //     cout<<root[i]<<" ";
        // }
        // cout<<endl;
        // for(int i=1;i<=n;i++){
        //     cout<<lst[i]<<" ";
        // }
        // cout<<endl;
    }
    for(int i=1;i<=n;i++){
        if(!v[i].empty()){
            for(int j=0;j<v[i].size();j++){
                cout<<v[i][j]<<" ";
            }
        }
    }
    return;
}

int32_t main(){
    int t=1;
    // scanf("%intd",&t);
    for(int i=0;i<t;i++){
        solve();
    }
    cerr <<endl<< "Time elapsed : " << clock() * 1000.0 / CLOCKS_PER_SEC << " ms" << '\n';
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
// #define int long long int
#define endl "\n"
#define F first
#define S second
#define mod 1000000007
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
int root[150005];
int sz[150005];
vector<int> v[150005];
int x,y,n,i,j;

int fndroot(int x){
    while(x != root[x]){
        x = root[root[x]];
    }
    return x;
}

void combine(int x,int y){
    int xrt = fndroot(x);
    int yrt = fndroot(y);
    if(xrt == yrt) return;
    if(sz[xrt]<sz[yrt]){
        root[xrt] = root[yrt];
        for(i=0;i<v[xrt].size();i++){
            v[yrt].push_back(v[xrt][i]);
        }
        v[xrt].clear();
    }else{
        root[yrt] = root[xrt];
        for(i=0;i<v[yrt].size();i++){
            v[xrt].push_back(v[yrt][i]);
        }
        v[yrt].clear();
    }
    return;
}

void solve(){
    cin>>n;
    for(i=1;i<=n;i++){
        root[i] = i;
        sz[i] = 1;
        v[i].push_back(i);
    }
    for(i=0;i<n-1;i++){
        cin>>x>>y;
        combine(x,y);
    }
    for(i=1;i<=n;i++){
        if(!v[i].empty()){
            for(j=0;j<v[i].size();j++){
                cout<<v[i][j]<<" ";
            }
        }
    }
    return;
}

int32_t main(){
    IOS;
    int t=1;
    // scanf("%intd",&t);
    for(i=0;i<t;i++){
        solve();
    }
    cerr <<endl<< "Time elapsed : " << clock() * 1000.0 / CLOCKS_PER_SEC << " ms" << '\n';
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define endl "\n"
#define F first
#define S second
#define mod 1000000007
int root[200005],lst[200005];

int fndroot(int x){
    while(x != root[x]){
        x = root[root[x]];
    }
    return x;
}

void combine(int x,int y){
    int xrt = fndroot(x);
    int yrt = fndroot(y);
    root[yrt] = lst[xrt];
    lst[xrt] = lst[yrt];
    return;
}

void solve(){
    int n;
    cin>>n;
    for(int i=1;i<=n;i++){
        root[i] = i;
        lst[i] = i;
    }
    for(int i=0;i<n-1;i++){
        int x,y;
        cin>>x>>y;
        combine(x,y);
        // for(int i=1;i<=n;i++){
        //     cout<<root[i]<<" ";
        // }
        // cout<<endl;
        // for(int i=1;i<=n;i++){
        //     cout<<lst[i]<<" ";
        // }
        // cout<<endl;
    }
    int st = lst[fndroot(1)];
    while (st != root[st])
    {
        cout<<st<<" ";
        st = root[st];
    }
    cout<<st<<endl;
    return;
}

int32_t main(){
    int t=1;
    // scanf("%lld",&t);
    for(int i=0;i<t;i++){
        solve();
    }
    cerr <<endl<< "Time elapsed : " << clock() * 1000.0 / CLOCKS_PER_SEC << " ms" << '\n';
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
// #define int long long int
#define endl "\n"
#define F first
#define S second
#define mod 1000000007
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
int root[150005];
int sz[150005];
vector<int> v[150005];

int fndroot(int x){
    while(x != root[x]){
        x = root[root[x]];
    }
    return x;
}

void combine(int x,int y){
    int xrt = fndroot(x);
    int yrt = fndroot(y);
    if(xrt == yrt) return;
    if(sz[xrt]<sz[yrt]){
        root[xrt] = root[yrt];
        for(int i=0;i<v[xrt].size();i++){
            v[yrt].push_back(v[xrt][i]);
        }
        v[xrt].clear();
    }else{
        root[yrt] = root[xrt];
        for(int i=0;i<v[yrt].size();i++){
            v[xrt].push_back(v[yrt][i]);
        }
        v[yrt].clear();
    }
    return;
}

void solve(){
    int n;
    cin>>n;
    for(int i=1;i<=n;i++){
        root[i] = i;
        sz[i] = 1;
        v[i].push_back(i);
    }
    for(int i=0;i<n-1;i++){
        int x,y;
        cin>>x>>y;
        combine(x,y);
        // for(int i=1;i<=n;i++){
        //     cout<<root[i]<<" ";
        // }
        // cout<<endl;
        // for(int i=1;i<=n;i++){
        //     cout<<lst[i]<<" ";
        // }
        // cout<<endl;
    }
    for(int i=1;i<=n;i++){
        if(!v[i].empty()){
            for(int j=0;j<v[i].size();j++){
                cout<<v[i][j]<<" ";
            }
        }
    }
    return;
}

int32_t main(){
    IOS;
    int t=1;
    // scanf("%intd",&t);
    for(int i=0;i<t;i++){
        solve();
    }
    cerr <<endl<< "Time elapsed : " << clock() * 1000.0 / CLOCKS_PER_SEC << " ms" << '\n';
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
// #define int long long int
#define endl "\n"
#define F first
#define S second
#define mod 1000000007
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
int root[150005];
int sz[150005];
vector<int> v[150005];
int x,y,n,i,j;

int fndroot(int x){
    while(x != root[x]){
        x = root[root[x]];
    }
    return x;
}

void combine(int x,int y){
    int xrt = fndroot(x);
    int yrt = fndroot(y);
    if(xrt == yrt) return;
    if(sz[xrt]<sz[yrt]){
        root[xrt] = root[yrt];
        for(i=0;i<v[xrt].size();i++){
            v[yrt].push_back(v[xrt][i]);
        }
        sz[yrt] += sz[xrt];
        v[xrt].clear();
    }else{
        root[yrt] = root[xrt];
        for(i=0;i<v[yrt].size();i++){
            v[xrt].push_back(v[yrt][i]);
        }
        sz[xrt] += sz[yrt];
        v[yrt].clear();
    }
    return;
}

void solve(){
    cin>>n;
    for(i=1;i<=n;i++){
        root[i] = i;
        sz[i] = 1;
        v[i].push_back(i);
    }
    for(i=0;i<n-1;i++){
        cin>>x>>y;
        combine(x,y);
    }
    for(i=1;i<=n;i++){
        if(!v[i].empty()){
            for(j=0;j<v[i].size();j++){
                cout<<v[i][j]<<" ";
            }
        }
    }
    return;
}

int32_t main(){
    IOS;
    int t=1;
    // scanf("%intd",&t);
    for(i=0;i<t;i++){
        solve();
    }
    cerr <<endl<< "Time elapsed : " << clock() * 1000.0 / CLOCKS_PER_SEC << " ms" << '\n';
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define endl "\n"
#define F first
#define S second
#define mod 1000000007
int root[200005];
int sz[150005];
vector<int> v[150005];

int fndroot(int x){
    while(x != root[x]){
        x = root[root[x]];
    }
    return x;
}

void combine(int x,int y){
    int xrt = fndroot(x);
    int yrt = fndroot(y);
    if(xrt == yrt) return;
    if(sz[xrt]<sz[yrt]){
        root[xrt] = root[yrt];
        for(int i=0;i<v[xrt].size();i++){
            v[yrt].push_back(v[xrt][i]);
        }
        v[xrt].clear();
    }else{
        root[yrt] = root[xrt];
        for(int i=0;i<v[yrt].size();i++){
            v[xrt].push_back(v[yrt][i]);
        }
        v[yrt].clear();
    }
    return;
}

void solve(){
    int n;
    cin>>n;
    for(int i=1;i<=n;i++){
        root[i] = i;
        sz[i] = 1;
        v[i].push_back(i);
    }
    for(int i=0;i<n-1;i++){
        int x,y;
        cin>>x>>y;
        combine(x,y);
        // for(int i=1;i<=n;i++){
        //     cout<<root[i]<<" ";
        // }
        // cout<<endl;
        // for(int i=1;i<=n;i++){
        //     cout<<lst[i]<<" ";
        // }
        // cout<<endl;
    }
    for(int i=1;i<=n;i++){
        if(!v[i].empty()){
            for(int j=0;j<v[i].size();j++){
                cout<<v[i][j]<<" ";
            }
        }
    }
    return;
}

int32_t main(){
    int t=1;
    // scanf("%intd",&t);
    for(int i=0;i<t;i++){
        solve();
    }
    cerr <<endl<< "Time elapsed : " << clock() * 1000.0 / CLOCKS_PER_SEC << " ms" << '\n';
    return 0;
}


#include<bits/stdc++.h>
#define ll long long int
#define ull unsigned long long int
#define ld long double
#define pb push_back
#define pf pop_front
#define mp make_pair
#define mod 1000000007
#define mat vector<vector<int>>
using namespace std;
#define F first
#define S second
#define int ll
#define for1(i,a,b) for(int i=a;i<b;i++)
#define all(x) x.begin(),x.end()
#define fo(i,n) for(int i=0;i<n;i++)
int max(auto a){int ans=-1e18;for(int i:a)if(i>ans)ans=i;return ans;}
int min(auto a){int ans=1e18;for(int i:a)if(i<ans)ans=i;return ans;}
void print(auto a){for(auto i:a)cout<<i<<' ';cout<<endl;}
#define inp(n) int n;cin>>n;
#define inpa(a,n) int a[n];fo(i,n)cin>>a[i];

signed main()
{

	inp(n)
	vector<pair<int,int>> conn[n];
	vector<pair<int,int>> p;
	fo(i,n-1)
	{
		inp(x) inp(y)
		x--,y--;
		p.pb(mp(x,y));
		conn[x].pb(mp(y,i));
		conn[y].pb(mp(x,i));
	}
	int ans[n]={0};
	priority_queue<int> pq;
	for(int i=0;i<conn[p[0].F].size();i++)
		pq.push(-conn[p[0].F][i].S);
	for(int i=0;i<conn[p[0].S].size();i++)
		pq.push(-conn[p[0].S][i].S);
	ans[0]=p[0].F;
	ans[1]=p[0].S;
	int curr=2;
	bool done[n]={0};
	bool done1[n-1]={0};
	done1[0]=1;
	done[p[0].F]=1;
	done[p[0].S]=1;
	while(pq.size()!=0 || curr<n)
	{
		int tp=-pq.top();
		done1[tp]=1;
		pq.pop();
		if(done[p[tp].S]==0)
		{
			done[p[tp].S]=1;
			int tpp=p[tp].S;
			ans[curr]=tpp;
			curr++;
			for(int j=0;j<conn[tpp].size();j++)
				if(done1[conn[tpp][j].S]==0)
					pq.push(-conn[tpp][j].S);
		}
		else if(done[p[tp].F]==0)
		{
			done[p[tp].F]=1;
			int tpp=p[tp].F;
			ans[curr]=tpp;
			curr++;
			for(int j=0;j<conn[tpp].size();j++)
				if(done1[conn[tpp][j].S]==0)
					pq.push(-conn[tpp][j].F);
		}
	}

	fo(i,n)cout<<ans[i]+1<<' ';cout<<endl;
}


#include<bits/stdc++.h>
#define ll long long int
#define ull unsigned long long int
#define ld long double
#define pb push_back
#define pf pop_front
#define mp make_pair
#define mod 1000000007
#define mat vector<vector<int>>
using namespace std;
#define F first
#define S second
#define int ll
#define for1(i,a,b) for(int i=a;i<b;i++)
#define all(x) x.begin(),x.end()
#define fo(i,n) for(int i=0;i<n;i++)
int max(auto a){int ans=-1e18;for(int i:a)if(i>ans)ans=i;return ans;}
int min(auto a){int ans=1e18;for(int i:a)if(i<ans)ans=i;return ans;}
void print(auto a){for(auto i:a)cout<<i<<' ';cout<<endl;}
#define inp(n) int n;cin>>n;
#define inpa(a,n) int a[n];fo(i,n)cin>>a[i];

signed main()
{

	inp(n)
	vector<pair<int,int>> conn[n];
	vector<pair<int,int>> p;
	fo(i,n-1)
	{
		inp(x) inp(y)
		x--,y--;
		p.pb(mp(x,y));
		conn[x].pb(mp(y,i));
		conn[y].pb(mp(x,i));
	}
	int ans[n]={0};
	priority_queue<int> pq;
	for(int i=0;i<conn[p[0].F].size();i++)
		pq.push(-conn[p[0].F][i].S);
	for(int i=0;i<conn[p[0].S].size();i++)
		pq.push(-conn[p[0].S][i].S);
	pq.pop();
	pq.pop();
	ans[0]=p[0].F;
	ans[1]=p[0].S;
	int curr=2;
	bool done[n]={0};
	bool done1[n-1]={0};
	done1[0]=1;
	done[p[0].F]=1;
	done[p[0].S]=1;
	while(pq.size()!=0)
	{
		int tp=-pq.top();
		done1[tp]=1;
		//cout<<tp<<endl;
		pq.pop();
		if(done[p[tp].S]==0)
		{
			done[p[tp].S]=1;
			int tpp=p[tp].S;
			ans[curr]=tpp;
			curr++;
			for(int j=0;j<conn[tpp].size();j++)
				if(done1[conn[tpp][j].S]==0)
					pq.push(-conn[tpp][j].S);
		}
		else if(done[p[tp].F]==0)
		{
			done[p[tp].F]=1;
			int tpp=p[tp].F;
			ans[curr]=tpp;
			curr++;
			for(int j=0;j<conn[tpp].size();j++)
				if(done1[conn[tpp][j].S]==0)
					pq.push(-conn[tpp][j].F);
		}
	}

	fo(i,n)cout<<ans[i]+1<<' ';cout<<endl;
}


#include<bits/stdc++.h>
#define ll long long int
#define pb push_back
#define pf pop_front
#define mp make_pair
using namespace std;

int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);

	ll n;
	cin>>n;
	ll x[n-1],y[n-1];
	for(int i=0;i<n-1;i++)
	{
		cin>>x[i]>>y[i];
		x[i]--;
		y[i]--;
	}
	deque<ll> space[n];
	int ct[n]={0};
	vector<ll> comp[n];
	ll ptr[n];
	for(int i=0;i<n;i++)
		comp[i].pb(i),ptr[i]=i,space[i].pb(i);

	vector<ll> adj[n];

	for(int i=0;i<n-1;i++)
	{
		if(comp[ptr[x[i]]].size()<comp[ptr[y[i]]].size())
		{
			for(int j=0;j<comp[ptr[x[i]]].size();j++)
				comp[ptr[y[i]]].pb(comp[ptr[x[i]]][j]),ptr[comp[ptr[x[i]]][j]]=ptr[x[i]];

			adj[space[ptr[y[i]]][0]].pb(space[ptr[x[i]]][0]);
			adj[space[ptr[x[i]]][0]].pb(space[ptr[y[i]]][0]);
			ct[space[ptr[y[i]]][0]]++;
			ct[space[ptr[x[i]]][0]]++;
			if(ct[space[ptr[y[i]]][0]]==2)
				space[ptr[y[i]]].pf();
			if(ct[space[ptr[x[i]]][0]]==2)
				space[ptr[x[i]]].pf();

			for(int j=0;j<space[ptr[x[i]]].size();j++)
				space[ptr[y[i]]].pb(space[ptr[x[i]]][j]);

		}
		else if(comp[ptr[x[i]]].size()>=comp[ptr[y[i]]].size())
		{
			int temp=y[i];
			y[i]=x[i];
			x[i]=temp;
			for(int j=0;j<comp[ptr[x[i]]].size();j++)
				comp[ptr[y[i]]].pb(comp[ptr[x[i]]][j]),ptr[comp[ptr[x[i]]][j]]=ptr[x[i]];

			adj[space[ptr[y[i]]][0]].pb(space[ptr[x[i]]][0]);
			adj[space[ptr[x[i]]][0]].pb(space[ptr[y[i]]][0]);
			ct[space[ptr[y[i]]][0]]++;
			ct[space[ptr[x[i]]][0]]++;
			if(ct[space[ptr[y[i]]][0]]==2)
				space[ptr[y[i]]].pf();
			if(ct[space[ptr[x[i]]][0]]==2)
				space[ptr[x[i]]].pf();

			for(int j=0;j<space[ptr[x[i]]].size();j++)
				space[ptr[y[i]]].pb(space[ptr[x[i]]][j]);

		}
	}

	ll curr;

	for(int i=0;i<n;i++)
	{
		if(adj[i].size()==1)
		{
			curr=i;break;
		}
		//for(int j=0;j<adj[i].size();j++)
		//	cout<<adj[i][j]+1<<' ';
		//cout<<endl;
	}

	bool done[n]={0};
	done[curr]=1;
	while(curr!=-1)
	{
		cout<<curr+1<<' ';
		if(done[adj[curr][0]]==0)
		{
			curr=adj[curr][0];
			done[adj[curr][0]]=1;
		}
		else if(adj[curr].size()==2 && done[adj[curr][1]]==0)
		{
			curr=adj[curr][1];
			done[adj[curr][1]]=1;
		}
		else
			curr=-1;
	}
	cout<<endl;
}


#include<bits/stdc++.h>
#define ll long long int
#define ull unsigned long long int
#define ld long double
#define pb push_back
#define pf pop_front
#define mp make_pair
#define mod 1000000007
#define mat vector<vector<int>>
using namespace std;
#define F first
#define S second
#define int ll
#define for1(i,a,b) for(int i=a;i<b;i++)
#define all(x) x.begin(),x.end()
#define fo(i,n) for(int i=0;i<n;i++)
int max(auto a){int ans=-1e18;for(int i:a)if(i>ans)ans=i;return ans;}
int min(auto a){int ans=1e18;for(int i:a)if(i<ans)ans=i;return ans;}
void print(auto a){for(auto i:a)cout<<i<<' ';cout<<endl;}
#define inp(n) int n;cin>>n;
#define inpa(a,n) int a[n];fo(i,n)cin>>a[i];

signed main()
{

	inp(n)
	vector<pair<int,int>> conn[n];
	vector<pair<int,int>> p;
	fo(i,n-1)
	{
		inp(x) inp(y)
		x--,y--;
		p.pb(mp(x,y));
		conn[x].pb(mp(y,i));
		conn[y].pb(mp(x,i));
	}
	int ans[n]={0};
	priority_queue<int> pq;
	for(int i=0;i<conn[p[0].F].size();i++)
		pq.push(-conn[p[0].F][i].S);
	for(int i=0;i<conn[p[0].S].size();i++)
		pq.push(-conn[p[0].S][i].S);
	pq.pop();
	pq.pop();
	ans[0]=p[0].F;
	ans[1]=p[0].S;
	int curr=2;
	bool done[n]={0};
	bool done1[n-1]={0};
	done1[0]=1;
	done[p[0].F]=1;
	done[p[0].S]=1;
	while(pq.size()!=0)
	{
		int tp=-pq.top();
		done1[tp]=1;
		//cout<<tp<<endl;
		pq.pop();
		if(done[p[tp].S]==0)
		{
			done[p[tp].S]=1;
			int tpp=p[tp].S;
			ans[curr]=tpp;
			curr++;
			for(int j=0;j<conn[tpp].size();j++)
				if(done1[conn[tpp][j].S]==0)
					pq.push(-conn[tpp][j].S);
		}
		else if(done[p[tp].F]==0)
		{
			done[p[tp].F]=1;
			int tpp=p[tp].F;
			ans[curr]=tpp;
			curr++;
			for(int j=0;j<conn[tpp].size();j++)
				if(done1[conn[tpp][j].S]==0)
					pq.push(-conn[tpp][j].S);
		}
	}

	fo(i,n)cout<<ans[i]+1<<' ';cout<<endl;
}


#include<bits/stdc++.h>
#define ll long long int
#define pb push_back
#define pf pop_front
#define mp make_pair
using namespace std;

int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);

	ll n;
	cin>>n;
	ll x[n-1],y[n-1];
	for(int i=0;i<n-1;i++)
	{
		cin>>x[i]>>y[i];
		x[i]--;
		y[i]--;
	}
	deque<ll> space[n];
	int ct[n]={0};
	vector<ll> comp[n];
	ll ptr[n];
	for(int i=0;i<n;i++)
		comp[i].pb(i),ptr[i]=i,space[i].pb(i);

	vector<ll> adj[n];

	for(int i=0;i<n-1;i++)
	{
		if(comp[ptr[x[i]]].size()<comp[ptr[y[i]]].size())
		{
			for(int j=0;j<comp[ptr[x[i]]].size();j++)
				comp[ptr[y[i]]].pb(comp[ptr[x[i]]][j]),ptr[comp[ptr[x[i]]][j]]=ptr[x[i]];

			adj[space[ptr[y[i]]][0]].pb(space[ptr[x[i]]][0]);
			adj[space[ptr[x[i]]][0]].pb(space[ptr[y[i]]][0]);
			ct[space[ptr[y[i]]][0]]++;
			ct[space[ptr[x[i]]][0]]++;
			if(ct[space[ptr[y[i]]][0]]==2)
				space[ptr[y[i]]].pf();
			if(ct[space[ptr[x[i]]][0]]==2)
				space[ptr[x[i]]].pf();

			for(int j=0;j<space[ptr[x[i]]].size();j++)
				space[ptr[y[i]]].pb(space[ptr[x[i]]][j]);

		}
		else if(comp[ptr[x[i]]].size()>=comp[ptr[y[i]]].size())
		{
			int temp=y[i];
			y[i]=x[i];
			x[i]=temp;
			for(int j=0;j<comp[ptr[x[i]]].size();j++)
				comp[ptr[y[i]]].pb(comp[ptr[x[i]]][j]),ptr[comp[ptr[x[i]]][j]]=ptr[x[i]];

			adj[space[ptr[y[i]]][0]].pb(space[ptr[x[i]]][0]);
			adj[space[ptr[x[i]]][0]].pb(space[ptr[y[i]]][0]);
			ct[space[ptr[y[i]]][0]]++;
			ct[space[ptr[x[i]]][0]]++;
			if(ct[space[ptr[y[i]]][0]]==2)
				space[ptr[y[i]]].pf();
			if(ct[space[ptr[x[i]]][0]]==2)
				space[ptr[x[i]]].pf();

			for(int j=0;j<space[ptr[x[i]]].size();j++)
				space[ptr[y[i]]].pb(space[ptr[x[i]]][j]);

		}
	}

	ll curr;

	for(int i=0;i<n;i++)
	{
		if(adj[i].size()==1)
		{
			curr=i;break;
		}
		//for(int j=0;j<adj[i].size();j++)
		//	cout<<adj[i][j]+1<<' ';
		//cout<<endl;
	}

	bool done[n]={0};
	done[curr]=1;
	while(curr!=-1)
	{
		cout<<curr+1<<' ';
		if(done[adj[curr][0]]==0)
		{
			curr=adj[curr][0];
			done[adj[curr][0]]=1;
		}
		else if(done[adj[curr][1]]==0)
		{
			curr=adj[curr][1];
			done[adj[curr][1]]=1;
		}
		else
			curr=-1;
	}
	cout<<endl;
}


#include<bits/stdc++.h>
#define ll long long int
#define ull unsigned long long int
#define ld long double
#define pb push_back
#define pf pop_front
#define mp make_pair
#define mod 1000000007
#define mat vector<vector<int>>
using namespace std;
#define F first
#define S second
#define int ll
#define for1(i,a,b) for(int i=a;i<b;i++)
#define all(x) x.begin(),x.end()
#define fo(i,n) for(int i=0;i<n;i++)
int max(auto a){int ans=-1e18;for(int i:a)if(i>ans)ans=i;return ans;}
int min(auto a){int ans=1e18;for(int i:a)if(i<ans)ans=i;return ans;}
void print(auto a){for(auto i:a)cout<<i<<' ';cout<<endl;}
#define inp(n) int n;cin>>n;
#define inpa(a,n) int a[n];fo(i,n)cin>>a[i];

signed main()
{

	inp(n)
	vector<pair<int,int>> conn[n];
	vector<pair<int,int>> p;
	fo(i,n-1)
	{
		inp(x) inp(y)
		x--,y--;
		p.pb(mp(x,y));
		conn[x].pb(mp(y,i));
		conn[y].pb(mp(x,i));
	}
	int ans[n]={0};
	bool done1[n-1]={0};
	priority_queue<int> pq;
	pq.push(0);
	int curr=0;
	bool done[n]={0};
	done1[0]=1;
	while(pq.size()!=0 || curr<n)
	{

		int tp=-pq.top();
		//cout<<tp<<' ';
		done1[tp]=1;
		pq.pop();
		if(done[p[tp].S]==0)
		{
			done[p[tp].S]=1;
			int tpp=p[tp].S;
			ans[curr]=tpp;
			curr++;
			for(int j=0;j<conn[tpp].size();j++)
				if(done1[conn[tpp][j].S]==0)
					pq.push(-conn[tpp][j].S),done1[conn[tpp][j].S]=1;
		}
		if(done[p[tp].F]==0)
		{
			done[p[tp].F]=1;
			int tpp=p[tp].F;
			ans[curr]=tpp;
			curr++;
			for(int j=0;j<conn[tpp].size();j++)
				if(done1[conn[tpp][j].S]==0)
					pq.push(-conn[tpp][j].F),done1[conn[tpp][j].S]=1;
		}
	}

	fo(i,n)cout<<ans[i]+1<<' ';cout<<endl;
}


#include<bits/stdc++.h>
#define ll long long int
#define ull unsigned long long int
#define ld long double
#define pb push_back
#define pf pop_front
#define mp make_pair
#define mod 1000000007
#define mat vector<vector<int>>
using namespace std;
#define F first
#define S second
#define int ll
#define for1(i,a,b) for(int i=a;i<b;i++)
#define all(x) x.begin(),x.end()
#define fo(i,n) for(int i=0;i<n;i++)
int max(auto a){int ans=-1e18;for(int i:a)if(i>ans)ans=i;return ans;}
int min(auto a){int ans=1e18;for(int i:a)if(i<ans)ans=i;return ans;}
void print(auto a){for(auto i:a)cout<<i<<' ';cout<<endl;}
#define inp(n) int n;cin>>n;
#define inpa(a,n) int a[n];fo(i,n)cin>>a[i];

signed main()
{

	inp(n)
	vector<pair<int,int>> conn[n];
	vector<pair<int,int>> p;
	fo(i,n-1)
	{
		inp(x) inp(y)
		x--,y--;
		p.pb(mp(x,y));
		conn[x].pb(mp(y,i));
		conn[y].pb(mp(x,i));
	}
	int ans[n]={0};
	bool done1[n-1]={0};
	priority_queue<int> pq;
	for(int i=0;i<conn[p[0].F].size();i++)
		pq.push(-conn[p[0].F][i].S),done1[conn[p[0].S][i].S]=1;
	for(int i=0;i<conn[p[0].S].size();i++)
		pq.push(-conn[p[0].S][i].S),done1[conn[p[0].S][i].S]=1;
	ans[0]=p[0].F;
	ans[1]=p[0].S;
	int curr=2;
	bool done[n]={0};

	done1[0]=1;
	done[p[0].F]=1;
	done[p[0].S]=1;
	while(pq.size()!=0 || curr<n)
	{
		int tp=-pq.top();
		done1[tp]=1;
		pq.pop();
		if(done[p[tp].S]==0)
		{
			done[p[tp].S]=1;
			int tpp=p[tp].S;
			ans[curr]=tpp;
			curr++;
			for(int j=0;j<conn[tpp].size();j++)
				if(done1[conn[tpp][j].S]==0)
					pq.push(-conn[tpp][j].S),done1[conn[tpp][j].S]=1;
		}
		else if(done[p[tp].F]==0)
		{
			done[p[tp].F]=1;
			int tpp=p[tp].F;
			ans[curr]=tpp;
			curr++;
			for(int j=0;j<conn[tpp].size();j++)
				if(done1[conn[tpp][j].S]==0)
					pq.push(-conn[tpp][j].F),done1[conn[tpp][j].S]=1;
		}
	}

	fo(i,n)cout<<ans[i]+1<<' ';cout<<endl;
}


#include<bits/stdc++.h>
#define ll long long int
#define pb push_back
#define pf pop_front
#define mp make_pair
using namespace std;

int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);

	ll n;
	cin>>n;
	ll x[n-1],y[n-1];
	for(int i=0;i<n-1;i++)
	{
		cin>>x[i]>>y[i];
		x[i]--;
		y[i]--;
	}
	deque<ll> space[n];
	int ct[n]={0};
	vector<ll> comp[n];
	ll ptr[n];
	for(int i=0;i<n;i++)
		comp[i].pb(i),ptr[i]=i,space[i].pb(i);

	vector<ll> adj[n];

	for(int i=0;i<n-1;i++)
	{
		if(comp[ptr[x[i]]].size()<comp[ptr[y[i]]].size())
		{
			for(int j=0;j<comp[ptr[x[i]]].size();j++)
				comp[ptr[y[i]]].pb(comp[ptr[x[i]]][j]),ptr[comp[ptr[x[i]]][j]]=ptr[x[i]];

			adj[space[ptr[y[i]]][0]].pb(space[ptr[x[i]]][0]);
			adj[space[ptr[x[i]]][0]].pb(space[ptr[y[i]]][0]);
			ct[space[ptr[y[i]]][0]]++;
			ct[space[ptr[x[i]]][0]]++;
			if(ct[space[ptr[y[i]]][0]]==2)
				space[ptr[y[i]]].pf();
			if(ct[space[ptr[x[i]]][0]]==2)
				space[ptr[x[i]]].pf();

			for(int j=0;j<space[ptr[x[i]]].size();j++)
				space[ptr[y[i]]].pb(space[ptr[x[i]]][j]);

		}
		else if(comp[ptr[x[i]]].size()>=comp[ptr[y[i]]].size())
		{
			int temp=y[i];
			y[i]=x[i];
			x[i]=temp;
			for(int j=0;j<comp[ptr[x[i]]].size();j++)
				comp[ptr[y[i]]].pb(comp[ptr[x[i]]][j]),ptr[comp[ptr[x[i]]][j]]=ptr[x[i]];

			adj[space[ptr[y[i]]][0]].pb(space[ptr[x[i]]][0]);
			adj[space[ptr[x[i]]][0]].pb(space[ptr[y[i]]][0]);
			ct[space[ptr[y[i]]][0]]++;
			ct[space[ptr[x[i]]][0]]++;
			if(ct[space[ptr[y[i]]][0]]==2)
				space[ptr[y[i]]].pf();
			if(ct[space[ptr[x[i]]][0]]==2)
				space[ptr[x[i]]].pf();

			for(int j=0;j<space[ptr[x[i]]].size();j++)
				space[ptr[y[i]]].pb(space[ptr[x[i]]][j]);

		}
	}

	ll curr;

	for(int i=0;i<n;i++)
	{
		if(adj[i].size()==1)
		{
			curr=i;break;
		}
		//for(int j=0;j<adj[i].size();j++)
		//	cout<<adj[i][j]+1<<' ';
		//cout<<endl;
	}

	bool done[n]={0};
	done[curr]=1;
	for(int i=0;i<n;i++)
	{
		cout<<curr+1<<' ';
		if(done[adj[curr][0]]==0)
		{
			curr=adj[curr][0];
			done[adj[curr][0]]=1;
		}
		else if(adj[curr].size()==2 && done[adj[curr][1]]==0)
		{
			curr=adj[curr][1];
			done[adj[curr][1]]=1;
		}
		else
			curr=-1;
	}
	cout<<endl;
}


#include<bits/stdc++.h>
#define ll long long int
#define ull unsigned long long int
#define ld long double
#define pb push_back
#define pf pop_front
#define mp make_pair
#define mod 1000000007
#define mat vector<vector<int>>
using namespace std;
#define F first
#define S second
#define int ll
#define for1(i,a,b) for(int i=a;i<b;i++)
#define all(x) x.begin(),x.end()
#define fo(i,n) for(int i=0;i<n;i++)
int max(auto a){int ans=-1e18;for(int i:a)if(i>ans)ans=i;return ans;}
int min(auto a){int ans=1e18;for(int i:a)if(i<ans)ans=i;return ans;}
void print(auto a){for(auto i:a)cout<<i<<' ';cout<<endl;}
#define inp(n) int n;cin>>n;
#define inpa(a,n) int a[n];fo(i,n)cin>>a[i];

signed main()
{

	inp(n)
	vector<int> conn[n];
	vector<pair<int,int>> p;
	fo(i,n-1)
	{
		inp(x) inp(y)
		x--,y--;
		p.pb(mp(x,y));
		conn[x].pb(i);
		conn[y].pb(i);
	}
	int ans[n]={0};
	bool done1[n-1]={0};
	priority_queue<int> pq;
	pq.push(0);
	int curr=0;
	bool done[n]={0};
	done1[0]=1;
	while(pq.size()!=0 || curr<n)
	{

		int tp=-pq.top();
		//cout<<tp<<' ';
		done1[tp]=1;
		pq.pop();
		if(done[p[tp].S]==0)
		{
			done[p[tp].S]=1;
			int tpp=p[tp].S;
			ans[curr]=tpp;
			curr++;
			for(int j=0;j<conn[tpp].size();j++)
				if(done1[conn[tpp][j]]==0)
					pq.push(-conn[tpp][j]),done1[conn[tpp][j]]=1;
		}
		if(done[p[tp].F]==0)
		{
			done[p[tp].F]=1;
			int tpp=p[tp].F;
			ans[curr]=tpp;
			curr++;
			for(int j=0;j<conn[tpp].size();j++)
				if(done1[conn[tpp][j]]==0)
					pq.push(-conn[tpp][j]),done1[conn[tpp][j]]=1;
		}
	}

	fo(i,n)cout<<ans[i]+1<<' ';cout<<endl;
}


#include<bits/stdc++.h>
#define ll long long int
#define ull unsigned long long int
#define ld long double
#define pb push_back
#define pf pop_front
#define mp make_pair
#define mod 1000000007
#define mat vector<vector<int>>
using namespace std;
#define F first
#define S second
#define int ll
#define for1(i,a,b) for(int i=a;i<b;i++)
#define all(x) x.begin(),x.end()
#define fo(i,n) for(int i=0;i<n;i++)
int max(auto a){int ans=-1e18;for(int i:a)if(i>ans)ans=i;return ans;}
int min(auto a){int ans=1e18;for(int i:a)if(i<ans)ans=i;return ans;}
void print(auto a){for(auto i:a)cout<<i<<' ';cout<<endl;}
#define inp(n) int n;cin>>n;
#define inpa(a,n) int a[n];fo(i,n)cin>>a[i];

signed main()
{

	inp(n)
	vector<pair<int,int>> conn[n];
	vector<pair<int,int>> p;
	fo(i,n-1)
	{
		inp(x) inp(y)
		p.pb(mp(x,y));
		x--,y--;
		conn[x].pb(mp(y,i));
		conn[y].pb(mp(x,i));
	}
	int ans[n];
	int curr=0;
	int done[n]={0};
	fo(i,n-1)
	{
		if(done[i]==0)
		{
			done[i]=1;
			ans[curr]=i;
			curr++;
			fo(j,conn[i].size())
			{
				ans[curr]=conn[i][j].F;
				done[conn[i][j].S]=1;
				curr++;
			}
		}
	}
	fo(i,n)cout<<ans[i]+1<<' ';cout<<endl;
}