#P12852. [NERC 2020 Online] Color the Tree

    ID: 12629 Type: RemoteJudge 2000ms 512MiB Tried: 0 Accepted: 0 Difficulty: (None) Uploaded By: Tags>2020Special JudgeICPCNERC/NEERC

[NERC 2020 Online] Color the Tree

题目描述

Christina has a rooted tree with nn vertices. Initially, all vertices are colored green, except for the root, which is colored red. Christina thinks that the tree is beautiful\emph{beautiful} if two rules are satisfied:

  • The root is colored red.
  • If the vertex is colored red, all vertices on the shortest path between it and the root are also red.

Christina repeatedly performs the following operation on the tree --- chooses a vertex and changes its color (if it was red, colors it green; if it was green, colors it red). The following rules must be satisfied while performing the operations:

  • The tree should stay beautiful.
  • The coloring of vertices should be unique. That means there is no moment in the past when each vertex had the same color as it has right now.

Your task is to help Christina build the longest possible sequence of operations following the rules.

输入格式

The first line contains an integer nn (1n201 \le n \le 20) --- the number of vertices in the tree.

The second line contains n1n - 1 integers pip_i (1pii1 \le p_i \le i for 1in11 \le i \le n - 1), denoting parent vertices in the tree. The vertices in the tree are numbered from 11 to nn, the root has number 11, the ii-th vertex has parent pi1p_{i-1} for 2in2 \le i \le n.

输出格式

On the first line output an integer mm --- the maximum number of operations.

On the second line output mm integers oio_i (2oin)2 \le o_i \le n). oio_i is the number of the vertex that changes color during the corresponding operation.

If there are several possible longest sequences, output any one of them.

4
1 1 1
7
4 3 4 2 4 3 4
4
1 2 3
3
2 3 4
6
1 1 2 2 2
17
3 2 3 6 3 5 3 6 3 4 3 6 3 5 3 6 3
5
1 2 1 1
11
5 4 5 2 5 4 5 3 5 4 5
5
1 1 2 3
8
3 5 2 5 3 4 3 5