并查集思路 n=int(input()) tree=list(map(int,input().split())) parent=list(map(int,input().split())) v=[i+1 for i in range(len(tree))] for i in range(len(parent)): if tree[i+1]>tree[parent[i]-1]: v[i+1]=v[parent[i]-1] v=map(str,v) print(' '.join(v))