inlineintinp(){ char c = getchar(); while(c < '0' || c > '9') c = getchar(); int sum = 0; while(c >= '0' && c <= '9'){ sum = sum * 10 + c - '0'; c = getchar(); } return sum; }
int a1[200010]; int a2[200010]; int fa[200010];
inlineboolrel(int a, int b){ // 判断b是否有 b ∈ { a_{a1}, a_{a2} } return (b == a1[a] || b == a2[a]); }
intmain(){ int n = inp(); if(n == 3){ printf("1 2 3"); return0; } for(int i = 1; i <= n; i++){ a1[i] = inp(); a2[i] = inp(); } for(int i = 1; i <= n; i++){ if(rel(a1[i], a2[i])) fa[i] = a1[i]; else fa[i] = a2[i]; } int cur = 1; while(fa[cur] != 1){ printf("%d ", cur); cur = fa[cur]; } printf("%d\n", cur); }