import sys
sys.setrecursionlimit(10**9)

pos=-1
def dfs(G,v,p):
    global pos
    seen[v]=True
    hist.append(v)
    for nv in G[v]:
        if nv==p:
            continue
        if finished[nv]:
            continue
        if seen[nv] and (not finished[nv]):
            pos=nv
            return
        dfs(G,nv,v)
        if pos!=-1:
            return
    hist.pop()
    finished[v]=True

N=int(input())
G=[[] for _ in range(N)]
Edge=[]
for i in range(N):
    a,b=map(lambda x:int(x)-1,input().split())
    G[a].append(b)
    G[b].append(a)
    Edge.append((a,b))
    
seen=[False]*N
finished=[False]*N
hist=[]
dfs(G,0,-1)
cycle=set()
while(hist):
    t=hist[-1]
    cycle.add(t)
    hist.pop()
    if t==pos:
        break
ans=[]
for i,e in enumerate(Edge):
    if e[0] in cycle and e[1] in cycle:
        ans.append(i+1)
print(len(ans))
print(*ans)