# 題意：

$n\le 1,000,000$

# 代碼：

#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cstdlib>
using namespace std;
typedef long long ll;
char ch = getchar(); ll x = 0; int op = 1;
for(; !isdigit(ch); ch = getchar()) if(ch == '-') op = -1;
for(; isdigit(ch); ch = getchar()) x = (x<<1)+(x<<3)+ch-'0';
return x*op;
}
const int N = 2000010;
int n, cnt, flag, chk, tot, rt;
struct edge {
int to, nxt;
edge() {}
edge(int x, int y) { to = x; nxt = y; }
} e[N];
inline void dfs(int u, int lst) {
for(int i = head[u], v; i; i = e[i].nxt) if((v = e[i].to) != lst) {
dfs(v, u); f[u] = min(f[u], f[v]);//f[u]表示以u爲根的子樹中中序遍歷開頭的最小值
}
}
inline void get(int u, int lst) {
for(int i = head[u], v; i; i = e[i].nxt) if((v = e[i].to) != lst && f[v] == f[u]) get(v, u);
ans[++ tot] = u;
for(int i = head[u], v; i; i = e[i].nxt) if((v = e[i].to) != lst && f[v] != f[u]) get(v, u);
}
int main() {
/*freopen("binary.in", "r", stdin);
freopen("binary.out", "w", stdout);*/
for(int i = 1; i <= n; i ++) {
for(int j = 1; j <= d[i]; j ++) {
}
}
for(int i = 1; i <= n; i ++)
if(d[i] <= 2) { rt = i; break; }
for(int i = 1; i <= n; i ++) if(d[i] <= 2) f[i] = i; else f[i] = n+1;
dfs(rt, 0);// for(int i = 1; i <= n; i ++) printf("%d ", f[i]); puts("");
for(int u = rt, lst = 0; ; ) {
ans[++ tot] = u; int c[5], ch = 0;
for(int i = head[u], v; i; i = e[i].nxt) if((v = e[i].to) != lst) c[++ ch] = v;
if(!ch) break;
if(ch == 1) {
if(f[c[1]] < c[1]) { get(c[1], u); break; }
else { lst = u; u = c[1]; }
}
if(ch == 2) {
if(f[c[1]] > f[c[2]]) swap(c[1], c[2]);
get(c[1], u); lst = u; u = c[2];
}
}
for(int i = 1; i <= n; i ++) printf("%d ", ans[i]);
return 0;
}