提交时间:2023-08-24 11:23:42

运行 ID: 100001

#include<bits/stdc++.h> #define int long long using namespace std; namespace Fast{ inline int fr(){ int x = 0,f = 1; char c = getchar(); while (c < '0' || c > '9'){ if (c == '-'){ f = -1; } c = getchar(); } while (c >= '0' && c <= '9'){ x = (x << 1) + (x << 3) + (c ^ 48); c = getchar(); } return x * f; } inline void fw(int x){ if (x < 0){ x = -x; putchar('-'); } if (x > 9){ fw(x / 10); } putchar(x % 10 + 48); } } using namespace Fast; const int maxn = 505; int n,mp[1145][1145],tag[114514]; stack <int> s; void dfs(int x){ for (int y = 1;y <= maxn;y++){ if (mp[x][y] >= 1){ mp[x][y]--; mp[y][x]--; dfs(y); } } s.push(x); } signed main(){ n = fr(); for (int i = 1;i <= n;i++){ int u,v; u = fr(),v = fr(); mp[u][v]++; mp[v][u]++; tag[u]++; tag[v]++; } int root = 1; for (int i = 1;i <= maxn;i++){ if (tag[i] & 1){ root = i; break; } } dfs(root); while (!s.empty()){ fw((int)(s.top())); puts(""); s.pop(); } return 0; }