import sys # sys.setrecursionlimit(200005) int1 = lambda x: int(x)-1 p2D = lambda x: print(*x, sep="\n") def II(): return int(sys.stdin.readline()) def LI(): return list(map(int, sys.stdin.readline().split())) def LI1(): return list(map(int1, sys.stdin.readline().split())) def LLI(rows_number): return [LI() for _ in range(rows_number)] def LLI1(rows_number): return [LI1() for _ in range(rows_number)] def SI(): return sys.stdin.readline().rstrip() # dij = [(0, 1), (-1, 0), (0, -1), (1, 0)] dij = [(0, 1), (1, 0), (0, -1), (-1, 0)] # dij = [(0, 1), (-1, 0), (0, -1), (1, 0), (1, 1), (1, -1), (-1, 1), (-1, -1)] inf = 1 << 63 # md = 998244353 md = 10**9+7 def dfs(to, root=0): n = len(to) par = [-1]*n go = [True]*n stack = [root] loop = -1 while stack: u = stack.pop() if go[u]: go[u] = False stack.append(u) # toの変数注意 for v in to[u]: if v == par[u]: continue if not go[v]: return v, u, par stack.append(v) par[v] = u else: # toの変数注意 for v in to[u]: if v == par[u]: continue n = II() to = [[] for _ in range(n)] uvtoi = {} for i in range(n): u, v = LI1() to[u].append(v) to[v].append(u) uvtoi[u, v] = uvtoi[v, u] = i p, u, par = dfs(to, 0) uu = [p, u] while uu[-1] != p: v = par[uu[-1]] uu.append(v) ans = [] for u, v in zip(uu, uu[1:]): ans.append(uvtoi[u, v]+1) print(len(ans)) print(*ans)