/* -*- coding: utf-8 -*- * * 1254.cc: No.1254 補強への架け橋 - yukicoder */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; /* constant */ const int MAX_N = 100000; /* typedef */ typedef pair pii; typedef vector vpii; /* global variables */ vpii nbrs[MAX_N]; int ps[MAX_N], ds[MAX_N], cis[MAX_N]; int es[MAX_N]; /* subroutines */ /* main */ int main() { int n; scanf("%d", &n); for (int i = 0; i < n; i++) { int a, b; scanf("%d%d", &a, &b); a--, b--; nbrs[a].push_back(pii(b, i)); nbrs[b].push_back(pii(a, i)); } memset(ds, -1, sizeof(ds)); ps[0] = -1, ds[0] = 1; int l = -1, r = -1; for (int u = 0; u >= 0;) { if (cis[u] < nbrs[u].size() && nbrs[u][cis[u]].first == ps[u]) cis[u]++; if (cis[u] < nbrs[u].size()) { pii a = nbrs[u][cis[u]++]; int v = a.first, ei = a.second; es[ds[u]] = ei; if (ds[v] < 0) { ps[v] = u, ds[v] = ds[u] + 1; u = v; } else { l = ds[v], r = ds[u] + 1; break; } } else u = ps[u]; } //printf("l=%d, r=%d\n", l, r); printf("%d\n", r - l); for (int i = l; i < r; i++) { printf("%d", es[i] + 1); putchar(i + 1 < r ? ' ' : '\n'); } return 0; }