시간 제한 | 메모리 제한 | 제출 | 정답 | 맞은 사람 | 정답 비율 |
---|---|---|---|---|---|
2 초 | 256 MB | 6 | 3 | 3 | 100.000% |
You are given a rooted tree with $N$ vertices. The vertices are numbered $0, 1, \ldots, N-1$. The root is vertex $0$, and the parent of vertex $i$ $(i = 1, 2, \ldots, N-1)$ is Vertex $p_i$.
Initially, an integer $a_i$ is written in vertex $i$. Here, $(a_0, a_1, \ldots, a_{N-1})$ is a permutation of $(0, 1, \ldots, N-1)$.
You can execute the following operation at most $25\,000$ times. The goal is to make the value written in vertex $i$ equal to $i$.
Input is given in the following format:
$N$
$p_1$ $p_2$ ... $p_{N-1}$
$a_0$ $a_1$ ... $a_{N-1}$
In the first line, print the number of operations, $Q$. In the second through $(Q+1)$-th lines, print the chosen vertices in order.
$2 \leq N \leq 2000$, $0 \leq p_i \leq i-1$, $(a_0, a_1, \ldots, a_{N-1})$ is a permutation of $(0, 1, \ldots, N-1)$.
5 0 1 2 3 2 4 0 1 3
2 3 4
5 0 1 2 2 4 3 1 2 0
3 4 3 1
In Sample 1, after the first operation, the values written in vertex $0, 1, \ldots, 4$ are $4, 0, 1, 2, 3$.
In Sample 2, after the first operation, the values written in vertex $0, 1, \ldots, 4$ are $3, 1, 0, 2, 4$. After the second operation, the values written in vertex $0, 1, \ldots, 4$ are $1, 0, 2, 3, 4$.