You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

36 lines
896 B
C++

#define _CRT_SECURE_NO_WARNINGS
#define _SILENCE_CXX17_C_HEADER_DEPRECATION_WARNING
#include <bits/stdc++.h>
using namespace std;
const int N = 200100;
int adj[N], nxt[N], to[N], ecnt, deg[N];
bool vis[N];
inline void addEdge(int f, int t) {
ecnt++;
nxt[ecnt] = adj[f];
adj[f] = ecnt;
to[ecnt] = t;
}
int main() {
int n;
scanf("%d", &n);
for (int i = 1, u, v; i <= n; i++) {
scanf("%d%d", &u, &v);
addEdge(u, v);
addEdge(v, u);
deg[u]++, deg[v]++;
}
queue<int> q;
for (int i = 1; i <= n; i++) if (deg[i] == 1) q.push(i), vis[i] = true;
for (; !q.empty(); q.pop())
for (int e = adj[q.front()]; e; e = nxt[e])
if (--deg[to[e]] == 1)
q.push(to[e]), vis[to[e]] = true;
for (int i = 1; i <= n; i++) if (!vis[i]) printf("%d ", i);
return 0;
}