import sys,os,io input = sys.stdin.readline class Graph: def __init__(self, N): self.V = N self.edge = [[] for _ in range(self.V)] self.edges = [0]*(N*2+1) self.visited = [False]*N self.parent = [N]*N def add_edge(self, a, b, i): self.edge[a].append((b,i)) self.edges[i] = (a,b) def dfs(self, start): stack = [start] self.parent[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 bfs(self, start): from collections import deque from copy import copy d = deque() d.append(dict()) cyc = dict() cnt = 0 while len(d)>0 and cnt<5*N: es = d.popleft() if len(es): v0,v = self.edges[list(es.keys())[-1]] else: v0,v = start,start for w,i in self.edge[v]: if w==v0: continue if w==start: dic = copy(es) dic[i] = True for i in range(N+1,2*N+1): if i in dic: dic[i-N] = True del dic[i] if len(dic)>len(cyc): cyc = dic if w not in es: dic = copy(es) dic[i] = True d.append(dic) cnt += 1 return cyc N = int(input()) G = Graph(N) for i in range(N): a,b = map(int, input().split()) G.add_edge(a-1,b-1,i+1) G.add_edge(b-1,a-1,N+i+1) ans = set() cyc = G.dfs(0) es = G.bfs(cyc) for e in es.keys(): ans.add(e) ans = list(ans) print(len(ans)) print(*ans)