#include <bits/stdc++.h>
using namespace std;

using graph = vector<vector<int>>;

vector<int> dfs(int v, int p, vector<bool> &visited, const graph &to, vector<int> &route) {
    visited.at(v) = true;
    for (int next : to.at(v)) {
        if (next == p) continue;
        route.push_back(v);
        if (visited.at(next)) {
            route.push_back(next);
            return route;
        }
        auto res = dfs(next, v, visited, to, route);
        if (not res.empty()) return res;
        route.pop_back();
    }
    return {};
}

int main() {
    int n;
    cin >> n;
    vector<int> a(n), b(n);
    for (int i = 0; i < n; i++) {
        cin >> a.at(i) >> b.at(i);
        a.at(i)--;
        b.at(i)--;
    }
    graph to(n);
    for (int i = 0; i < n; i++) {
        to.at(a.at(i)).push_back(b.at(i));
        to.at(b.at(i)).push_back(a.at(i));
    }
    vector<int> route;
    vector<bool> visited(n);
    auto res = dfs(0, -1, visited, to, route);
    int s = res.back();
    res.pop_back();
    reverse(res.begin(), res.end());
    vector<bool> inloop(n);
    for (int v : res) {
        inloop.at(v) = true;
        if (v == s) break;
    }
    cout << count(inloop.begin(), inloop.end(), true) << endl;
    for (int i = 0; i < n; i++) {
        if (inloop.at(a.at(i)) and inloop.at(b.at(i))) {
            cout << i + 1 << " ";
        }
    }
    cout << endl;
}