输入 6
1 2 1 3 3 (i+2与l[i]相连,其中i从1开始)
输出 4 5 6 1 3 2
数组 i ... (2~n)
f(i) ...
n = int(input())
l = list(map(int,input().split()))
#M = [[0]*(n+1) for _ in range(n+1)]
d = {}
stack = []
out = []
for i in range(2,n+1): #2...n
if i not in d:
d[i]=[]
d[i].append(l[i-2])
if l[i-2] not in d:
d[l[i-2]]=[]
d[l[i-2]].append(i)
print(d)
def parent(d):
res = []
for x in d:
if len(d[x])==1:
res.append(x)
d[x]=[]
return d,res
d,res = parent(d)
stack = res
while stack:
p = stack.pop(0) #从左边pop(0) , 默认从末尾pop
out.append(p)
if p in d:
d[p]=[]
for x in d:
if p in d[x]:
d[x].remove(p)
if len(d[x])==1:
stack=stack+[x]
print(out)