#define _USE_MATH_DEFINES #include using namespace std; #define FOR(i,m,n) for(int i=(m);i<(n);++i) #define REP(i,n) FOR(i,0,n) #define ALL(v) (v).begin(),(v).end() using ll = long long; constexpr int INF = 0x3f3f3f3f; constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL; constexpr double EPS = 1e-8; constexpr int MOD = 1000000007; // constexpr int MOD = 998244353; constexpr int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1}; constexpr int dy8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dx8[] = {0, -1, -1, -1, 0, 1, 1, 1}; template inline bool chmax(T &a, U b) { return a < b ? (a = b, true) : false; } template inline bool chmin(T &a, U b) { return a > b ? (a = b, true) : false; } struct IOSetup { IOSetup() { std::cin.tie(nullptr); std::ios_base::sync_with_stdio(false); std::cout << fixed << setprecision(20); } } iosetup; template struct Edge { int src, dst; CostType cost; Edge(int src, int dst, CostType cost = 0) : src(src), dst(dst), cost(cost) {} inline bool operator<(const Edge &x) const { return cost != x.cost ? cost < x.cost : dst != x.dst ? dst < x.dst : src < x.src; } inline bool operator<=(const Edge &x) const { return !(x < *this); } inline bool operator>(const Edge &x) const { return x < *this; } inline bool operator>=(const Edge &x) const { return !(*this < x); } }; template struct UnicyclicGraph { std::vector> loop; std::vector is_in_loop; std::vector>>> forest; std::vector belong, mp; std::vector> inv; UnicyclicGraph(int n) : n(n), is_in_loop(n, false), belong(n, -1), mp(n, -1), graph(n) {} void add_edge(int src_i, int dst_i, CostType cost_i) { int id = src.size(); graph[src_i].emplace_back(id); graph[dst_i].emplace_back(id); src.emplace_back(src_i); dst.emplace_back(dst_i); cost.emplace_back(cost_i); } void build() { dfs(-1, 0); for (int i = 0; i < n; ++i) { if (is_in_loop[i] && graph[i].size() > 2) { int idx = forest.size(); forest.emplace_back(std::vector>>(1)); belong[i] = idx; mp[i] = 0; inv.emplace_back(std::vector{i}); std::queue que({i}); while (!que.empty()) { int ver = que.front(); que.pop(); for (int id : graph[ver]) { int to = destination(id, ver); if (belong[to] == -1 && !is_in_loop[to]) { int nx = forest[idx].size(); forest[idx].emplace_back(); forest[idx][mp[ver]].emplace_back(mp[ver], nx, cost[id]); forest[idx][nx].emplace_back(nx, mp[ver], cost[id]); belong[to] = idx; mp[to] = nx; inv[idx].emplace_back(to); que.emplace(to); } } } } } } private: int n; std::vector> graph; std::vector src, dst; std::vector cost; int destination(int id, int s) const { return src[id] == s ? dst[id] : src[id]; } bool dfs(int prev_id, int ver) { is_in_loop[ver] = true; for (int id : graph[ver]) { if (id != prev_id) { int to = destination(id, ver); loop.emplace_back(ver, to, cost[id]); if (is_in_loop[to]) { for (int i = static_cast(loop.size()) - 2; i >= 0; --i) { if (loop[i].src == to) { for (int j = 0; j < i; ++j) is_in_loop[loop[j].src] = false; loop.erase(loop.begin(), loop.begin() + i); break; } } return true; } if (dfs(id, to)) return true; loop.pop_back(); } } is_in_loop[ver] = false; return false; } }; int main() { int n; std::cin >> n; std::map, int> edge; UnicyclicGraph namori(n); for (int i = 0; i < n; ++i) { int a, b; std::cin >> a >> b; --a; --b; if (a > b) std::swap(a, b); edge[{a, b}] = i; namori.add_edge(a, b, false); } namori.build(); std::vector bridge(n, false); for (const Edge &e : namori.loop) { int a = e.src, b = e.dst; if (a > b) std::swap(a, b); bridge[edge[{a, b}]] = true; } std::vector p; for (int i = 0; i < n; ++i) { if (bridge[i]) p.emplace_back(i); } int k = p.size(); std::cout << k << '\n'; for (int i = 0; i < k; ++i) std::cout << p[i] + 1 << " \n"[i + 1 == k]; return 0; }