import sys sys.setrecursionlimit(10**6) N=int(input()) g=[[] for i in range(N+1)] d=[0]*(N+1) e=[] ok=[True]*(N+1) id=dict() for i in range(N): a,b=map(int,input().split()) g[a].append(b) g[b].append(a) d[a]+=1 d[b]+=1 e.append((a,b)) stk=[] for i in range(N): if d[i+1]==1: stk.append(i+1) while stk: v=stk.pop() if d[v]<=0: continue for u in g[v]: d[u]-=1 d[v]-=1 if d[u]==1: stk.append(u) ans=[] for i in range(N): if d[e[i][0]]>0 and d[e[i][1]]>0: ans.append(i+1) print(len(ans)) print(*ans)