Color the Tree
시간 제한2초메모리 제한512 MB
정점이 20개 이하인 루트 트리에서, 트리가 아름다운 상태를 유지하면서 이전에 나온 적 없는 색 배치만 등장하도록 색을 바꾸는 최장 수열을 구합니다.
문제
Christina has a rooted tree with vertices. Initially, all vertices are colored green, except for the root, which is colored red. Christina thinks that the tree is 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 () --- the number of vertices in the tree.
The second line contains integers ( for ), denoting parent vertices in the tree. The vertices in the tree are numbered from to , the root has number , the -th vertex has parent for .
출력
On the first line output an integer --- the maximum number of operations.
On the second line output integers (. 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.