#include <stdio.h>
#include <bits/stdc++.h>

#include <algorithm>
#include <cassert>
#include <vector>

namespace atcoder {

// Implement (union by size) + (path compression)
// Reference:
// Zvi Galil and Giuseppe F. Italiano,
// Data structures and algorithms for disjoint set union problems
struct dsu {
  public:
    dsu() : _n(0) {}
    dsu(int n) : _n(n), parent_or_size(n, -1) {}

    int merge(int a, int b) {
        assert(0 <= a && a < _n);
        assert(0 <= b && b < _n);
        int x = leader(a), y = leader(b);
        if (x == y) return x;
        if (-parent_or_size[x] < -parent_or_size[y]) std::swap(x, y);
        parent_or_size[x] += parent_or_size[y];
        parent_or_size[y] = x;
        return x;
    }

    bool same(int a, int b) {
        assert(0 <= a && a < _n);
        assert(0 <= b && b < _n);
        return leader(a) == leader(b);
    }

    int leader(int a) {
        assert(0 <= a && a < _n);
        if (parent_or_size[a] < 0) return a;
        return parent_or_size[a] = leader(parent_or_size[a]);
    }

    int size(int a) {
        assert(0 <= a && a < _n);
        return -parent_or_size[leader(a)];
    }

    std::vector<std::vector<int>> groups() {
        std::vector<int> leader_buf(_n), group_size(_n);
        for (int i = 0; i < _n; i++) {
            leader_buf[i] = leader(i);
            group_size[leader_buf[i]]++;
        }
        std::vector<std::vector<int>> result(_n);
        for (int i = 0; i < _n; i++) {
            result[i].reserve(group_size[i]);
        }
        for (int i = 0; i < _n; i++) {
            result[leader_buf[i]].push_back(i);
        }
        result.erase(
            std::remove_if(result.begin(), result.end(),
                           [&](const std::vector<int>& v) { return v.empty(); }),
            result.end());
        return result;
    }

  private:
    int _n;
    // root node: -1 * component size
    // otherwise: parent
    std::vector<int> parent_or_size;
};

}  // namespace atcoder

using namespace atcoder;
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define Inf 2000000001

vector<int> get(int x,vector<vector<int>> E){
	vector<int> ret(E.size(),Inf);
	ret[x] = 0;
	queue<int> Q;
	Q.push(x);
	
	while(Q.size()!=0){
		int u = Q.front();
		Q.pop();
		rep(i,E[u].size()){
			int v = E[u][i];
			if(ret[v]!=Inf)continue;
			ret[v] = ret[u]+1;
			Q.push(v);
		}
	}
	return ret;
}

int main(){	

	int n;
	cin>>n;
	
	dsu D(n);
	vector<int> u(n),v(n);
	int x,y;
	int z;
	vector<vector<int>> E(n,vector<int>());
	rep(i,n){
		cin>>u[i]>>v[i];
		u[i]--;
		v[i]--;
		
		if(D.same(u[i],v[i])){
			x = u[i];
			y = v[i];
			z = i;
		}
		else{
			D.merge(u[i],v[i]);
			E[u[i]].push_back(v[i]);
			E[v[i]].push_back(u[i]);
		}
	}
	
	vector<int> a = get(x,E),b = get(y,E);
	
	int d = a[y];
	vector<int> ans;
	rep(i,n){
		if(i==z)ans.push_back(i);
		else{
			if(a[u[i]]+b[v[i]]+1==d || b[u[i]]+a[v[i]]+1==d)ans.push_back(i);
		}
	}
	
	cout<<ans.size()<<endl;
	rep(i,ans.size()){
		if(i!=0)cout<<' ';
		cout<<ans[i]+1;
	}
	cout<<endl;

    return 0;
}