//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = int64_t;
using ld = long double;
using P = pair<int, int>;
using vs = vector<string>;
using vi = vector<int>;
using vvi = vector<vi>;
template<class T> using PQ = priority_queue<T>;
template<class T> using PQG = priority_queue<T, vector<T>, greater<T> >;
const int INF = 0xccccccc;
const ll LINF = 0xcccccccccccccccLL;
template<typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) {return a < b && (a = b, true);}
template<typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) {return a > b && (a = b, true);}
template<typename T1, typename T2>
istream &operator>>(istream &is, pair<T1, T2> &p) { return is >> p.first >> p.second;}
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) { return os << p.first << ' ' << p.second;}

struct TECC {
	struct Edge {
		int to, rev;
		Edge() {}
		Edge(int t, int r):to(t), rev(r) {}
	};
	int n;
	vector<vector<Edge>> G;
	TECC(int n_) : n(n_), G(n_) {}
	void add(int u, int v) {
		G[u].emplace_back(v, int(G[v].size()));
		G[v].emplace_back(u, int(G[u].size())-1);
	}
	pair<int, vector<int>> tecc_ids() {
		int now_ord = 0, group_num = 0;
		vector<int> used, low(n), ord(n, -1), ids(n);
		used.reserve(n);
		auto dfs = [&](auto self, int v)->void {
			low[v] = ord[v] = now_ord++;
			used.push_back(v);
			for(Edge &e:G[v]) if(e.rev != -1) {
				int to = e.to;
				G[to][e.rev].rev = -1;
				e.rev = -1;
				if(ord[to] == -1) {
					self(self, to);
					low[v] = min(low[v], low[to]);
				}
				else {
					low[v] = min(low[v], ord[to]);
				}
			}
			if(low[v] == ord[v]) {
				int u;
				do {
					u = used.back();
					used.pop_back();
					ord[u] = n;
					ids[u] = group_num;
				} while(u != v);
				group_num++;
			}
		};
		for(int i = 0; i < n; i++) {
			if(ord[i] == -1) dfs(dfs, i);
		}
		for(int &x:ids) {
			x = group_num - 1 - x;
		}
		return {group_num, ids};
	}
	vector<vector<int>> tecc() {
		pair<int, vector<int>> ids = tecc_ids();
		int group_num = ids.first;
		vector<int> counts(group_num);
		for(int x:ids.second) counts[x]++;
		vector<vector<int>> groups(group_num);
		for(int i = 0; i < group_num; i++) {
			groups[i].reserve(counts[i]);
		}
		for(int i = 0; i < n; i++) {
			groups[ids.second[i]].push_back(i);
		}
		return groups;
	}
};

//head



int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	TECC tecc(n);
	vector<P> edges(n);
	rep(i, n) {
		int a, b;
		cin >> a >> b;
		edges[i] = {--a, --b};
		tecc.add(a, b);
	}
	vi ans;
	ans.reserve(n);
	vi info = tecc.tecc_ids().second;
	rep(i, n) {
		auto [u, v] = edges[i];
		if(info[u] == info[v]) ans.push_back(i+1);
	}
	cout << size(ans) << endl;
	for(int x:ans) cout << x << ' ';
	cout << endl;
}