import sys,os,io input = sys.stdin.readline from collections import defaultdict class Graph: def __init__(self, N): self.V = N self.edge = [[] for _ in range(self.V)] self.edges = defaultdict(lambda: 0) self.visited = [0]*N self.parent = [N]*N def add_edge(self, a, b, i): self.edge[a].append(b) self.edges[(a,b)] = i def dfs(self, start): stack = [start] self.parent[start] = -1 self.visited[start] = 1 #記録したい値の配列を定義 while stack: v = stack[-1] for u,i in self.edge[v]: if u==self.parent[v]: continue if self.parent[u]==N: #子へ降ろす self.parent[u]=v stack.append(u) break else: return u else: stack.pop() def bfs1(self, start): stack = deque([start]) self.parent[start] = -1 while stack: v = stack.pop() for u in self.edge[v]: if u==self.parent[v]: continue if self.parent[u]!=N: return u self.parent[u]=v #頂点に対する処理 stack.append(u) return def bfs(self, start): d = deque() d.append([[start],{start:True}]) cyc = [] length = [0]*self.V while len(d)>0: vs, tf = d.popleft() for w in self.edge[vs[-1]]: if len(vs)>1 and w==vs[-2]: continue cyc,dic = copy(vs), copy(tf) cyc.append(w) dic[w] = True if w==start: return cyc elif w not in tf: d.append([cyc,dic]) return cyc from collections import deque from copy import copy N = int(input()) G = Graph(N) for i in range(N): a,b = map(int, input().split()) a,b = min(a-1,b-1), max(a-1,b-1) G.add_edge(a,b,i+1) G.add_edge(b,a,i+1) ans = set() cyc = G.bfs1(0) vs = G.bfs(cyc) for v0,v1 in zip(vs[:-1],vs[1:]): ans.add(G.edges[(v0,v1)]) ans = list(ans) print(len(ans)) print(*ans)