#include int a[200005], b[200005]; int h[200005], l; int comp_h(int x, int y) { if (a[h[x]] > a[h[y]]) return 1; else return -1; } void swap_h(int x, int y) { int f = h[x]; h[x] = h[y]; h[y] = f; return; } void push(int ne) { h[l] = ne; int p = l; l++; for (; p > 0; p = (p - 1) / 2) if (comp_h((p - 1) / 2, p) > 0) swap_h((p - 1) / 2, p); return; } int pop() { l--; swap_h(0, l); int p = 0; for (;;) { if (2 * p + 2 < l) { if (comp_h(2 * p + 1, 2 * p + 2) > 0) { if (comp_h(p, 2 * p + 2) > 0) swap_h(p, 2 * p + 2); p = 2 * p + 2; } else { if (comp_h(p, 2 * p + 1) > 0) swap_h(p, 2 * p + 1); p = 2 * p + 1; } } else if (2 * p + 1 < l) { if (comp_h(p, 2 * p + 1) > 0) swap_h(p, 2 * p + 1); p = 2 * p + 1; } else break; } return h[l]; } int main() { int n; scanf("%d", &n); int i; for (i = 0; i < n; i++) { i *= 2; scanf("%d %d", &a[i], &b[i]); a[i]--; b[i]--; a[i + 1] = b[i]; b[i + 1] = a[i]; i /= 2; } l = 0; for (i = 0; i < 2 * n; i++) push(i); int c[200005]; for (i = 0; i < 2 * n; i++) c[i] = pop(); int cnt[100005]; for (i = 0; i < n; i++) cnt[i] = 0; for (i = 0; i < n; i++) { i *= 2; cnt[a[i]]++; cnt[b[i]]++; i /= 2; } int u[100005]; for (i = 0; i < n; i++) u[i] = 0; l = 0; for (i = 0; i < n; i++) { if (cnt[i] == 1) { h[l] = i; l++; } } int min, mid, max; c[2 * n] = 2 * n; a[2 * n] = -1; while (l > 0) { l--; i = h[l]; min = -1; max = 2 * n; while (max - min > 1) { mid = (max + min) / 2; if (a[c[mid]] < i) min = mid; else max = mid; } while (a[c[max]] == i) { cnt[b[c[max]]]--; u[c[max] / 2] = 1; if (cnt[b[c[max]]] == 1) { h[l] = b[c[max]]; l++; } max++; } } int k = 0; for (i = 0; i < n; i++) if (u[i] == 0) k++; printf("%d\n", k); for (i = 0; i < n; i++) { if (u[i] == 0) { printf("%d", i + 1); k--; if (k > 0) printf(" "); else printf("\n"); } } return 0; }