import sys def I(): return int(sys.stdin.readline().rstrip()) def MI(): return map(int,sys.stdin.readline().rstrip().split()) N = I() Graph = [[] for _ in range(N+1)] dict_edge = {} for i in range(1,N+1): a,b = MI() Graph[a].append(b) Graph[b].append(a) dict_edge[(a,b)] = i dict_edge[(b,a)] = i flag = [0]*(N+1) previous = [0]*(N+1) ANS = [] def dfs(i,par): flag[i] = 1 for j in Graph[i]: if j == par: continue elif flag[j] == 0: flag[j] = 1 previous[j] = i dfs(j,i) else: ANS.append(dict_edge[(i,j)]) k = i while k != j: ANS.append(dict_edge[k,previous[k]]) k = previous[k] break dfs(1,0) print(len(ANS)) print(*ANS)