HDRF

아직 제출이 없습니다시간 제한1초메모리 제한256 MB

문제

If you love Big Data, you should be familiar with running code in a distributed manner. This always requires lots of infrastructure elements working together to make the parallel computations possible. One of such elements is usually a scheduler that decides which scheduled tasks are to be started now in some "fair" and "efficient" way. 

Based on the nature of the tasks (testing, long-running, real-time, etc.), they are organized into hierarchical structure which can be represented as a rooted tree.

The following problem is inspired by one of the modern scheduling algorithms called Hierarchical Dominant Resource Fairness (HDRF).

You are given a rooted tree TT with root at vertex 11 which consists of nn vertices. Each vertex ii of the tree gets a unique priority v_iv\_i. For each vertex, we can compute the value r_ir\_i: the smallest v_iv\_i in the subtree of vertex ii including itself.

Consider the following tree traversal algorithm:

  • Start at the root vertex.
  • Choose the direct child of the current vertex which has the smallest value r_ir\_i.
  • Go to this child.
  • If the current vertex is a leaf, write it down and remove it from the tree (when we delete a vertex, we recompute all r_ir\_i). Otherwise, go to step 2.

Repeat the above procedure starting from step 1 until the tree is empty.

Given a tree TT and the numbers v_iv\_i, compute the order in which vertices will be written down.

입력

The first line contains an integer nn (2n100,0002 \leq n \leq 100\\,000), the number of vertices in the tree.

The second line contains n1n - 1 integers, where ii-th integer p_ip\_i (1p_in1 \leq p\_i \leq n) is the parent of vertex (i+1)(i + 1) in the tree. Vertices are numbered by integers from 11 to nn. It is guaranteed that the input forms a valid rooted tree with root at vertex 11.

The third line contains nn distinct integers v_1,v_2,,v_nv\_1, v\_2, \ldots, v\_n (0v_i1090 \leq v\_i \leq 10^9), the priorities of vertices.

출력

Output nn vertices in the order they will be written down by the algorithm.