from collections import defaultdict from typing import List import sys sys.setrecursionlimit(10**8) import pypyjit pypyjit.set_param("max_unroll_recursion=-1") input = sys.stdin.readline class UnionFind: """0-indexed""" def __init__(self, n): self.n = n self.parent = [-1] * n self.__group_count = n def unite(self, x, y) -> bool: """xとyをマージ""" x = self.root(x) y = self.root(y) if x == y: return False self.__group_count -= 1 if self.parent[x] > self.parent[y]: x, y = y, x self.parent[x] += self.parent[y] self.parent[y] = x return True def is_same(self, x, y) -> bool: """xとyが同じ連結成分か判定""" return self.root(x) == self.root(y) def root(self, x) -> int: """xの根を取得""" if self.parent[x] < 0: return x else: # 経路圧縮あり # self.parent[x] = self.root(self.parent[x]) # return self.parent[x] # 経路圧縮なし return self.root(self.parent[x]) def size(self, x) -> int: """xが属する連結成分のサイズを取得""" return -self.parent[self.root(x)] def all_sizes(self) -> List[int]: """全連結成分のサイズのリストを取得 O(N)""" sizes = [] for i in range(self.n): size = self.parent[i] if size < 0: sizes.append(-size) return sizes def members(self, x) -> List[int]: """xが属するグループのリストを返す O(N)""" mem = [] r = self.root(x) for i in range(self.n): if self.root(i) == r: mem.append(i) return mem def groups(self) -> List[List[int]]: """全連結成分の内容のリストを取得 O(N・α(N))""" groups = dict() for i in range(self.n): p = self.root(i) if not groups.get(p): groups[p] = [] groups[p].append(i) return list(groups.values()) @property def group_count(self) -> int: """連結成分の数を取得 O(1)""" return self.__group_count N = int(input()) uf = UnionFind(N) G = [list() for _ in range(N)] def dfs(v,p,start,f,edge): if v==start and f==True: return True elif v==start: f = True if len(G[v])==1: return False for nex in G[v]: if nex==p: continue if dfs(nex,v,start,f,edge): edge.append((nex,v)) return True d = defaultdict(int) for i in range(N): a, b = map(int, input().split()) a-=1;b-=1 G[a].append(b) G[b].append(a) d[str(a)+'_'+str(b)] = i+1 d[str(b)+'_'+str(a)] = i+1 if uf.is_same(a,b): edge = [] dfs(a,b,a,False,edge) print(len(edge)) ans = [] for u,v in edge: ans.append(d[str(u)+'_'+str(v)]) ans.sort() print(*ans) else: uf.unite(a,b)