Living on a Tree (tree)
Xiao Yi and Xiao Ai live on a tree. The tree $T$ has $n$ nodes and is connected by $n-1$ edges. There is a permutation $p$ on the tree. In each step, Xiao Ai can choose an edge $(u, v) \in T$ and swap $p_u$ and $p_v$. Xiao Ai's task is to sort the permutation. To estimate the minimum number of swaps required, Xiao Ai asks Xiao Yi for advice. After some thought, Xiao Yi writes down the following formula:
$$\frac{1}{2} \sum_{i=1}^{n} \text{dist}(i, p_i)$$
After trying, Xiao Ai discovers that, coincidentally, the current permutation exactly reaches the lower bound given by Xiao Yi! She wants to test you: can you provide a sorting scheme that reaches this lower bound? In particular, she also hopes that the scheme you provide has the lexicographically smallest order. We consider the edges on the tree to be numbered from $1$ to $n-1$, and the lexicographical order of the scheme is determined by comparing the indices of the edges used in sequence.
Input
The first line contains a positive integer $n$, representing the number of nodes in the tree.
The next $n-1$ lines each contain two positive integers $u_i, v_i$, representing the $i$-th edge ($1 \le i \le n-1$).
The next line contains $n$ positive integers, representing the permutation $p$.
Output
Output one line. Output the indices of the edges used in the lexicographically smallest solution in order.
Examples
Input 1
5 5 2 3 2 2 4 1 3 2 1 5 3 4
Output 1
2 1 3 4 2
Note 1
The initial sequence is $2, 1, 5, 3, 4$. During the following $5$ operations, the sequence becomes: $2, 5, 1, 3, 4$ $2, 4, 1, 3, 5$ $2, 3, 1, 4, 5$ $1, 3, 2, 4, 5$ * $1, 2, 3, 4, 5$
Examples 2
See tree/tree2.in and tree/tree2.ans in the contestant's directory.
Subtasks
For $100\%$ of the data, it is guaranteed that $1 \le n \le 10^3$, and the given permutation can be sorted within $\frac{1}{2} \sum_{i=1}^{n} \text{dist}(i, p_i)$ operations.
| Test Case | $n$ | Special Constraints |
|---|---|---|
| 1, 2 | $= 5$ | |
| 3, 4 | $= 30$ | |
| 5 | $= 10^2$ | |
| 6 | $= 10^3$ | A0 |
| 7 | $= 10^3$ | A1 |
| 8 | $= 10^3$ | B0 |
| 9 | $= 10^3$ | B1 |
| 10 | $= 10^3$ |
Special constraints: A represents the edge set $\{(1, 2), (2, 3), \dots, (n-1, n)\}$. B represents the edge set $\{(1, 2), (1, 3), \dots, (1, n)\}$. 0 indicates that the edges are guaranteed to be given in the order specified above. 1 indicates that they may be given in any order.