Task
You are given a tree with nodes, with root in node , and two arrays and , having elements, indexed from to .
It is guaranteed that each level of the tree contains at most nodes.
You have to select some nodes for which it is possible to choose:
- a subset of nodes on the path from the root to ; S(Y) can be empty
- a node that is a proper ancestor of both and all the nodes from .
Such as the following condition holds:
A proper ancestor of is any node such that node is an ancestor of node and is not the same node as .
Before solving the problem, just like Nea' Gigi, the owner of FCSB, often makes miraculous changes at halftime, you are allowed to make changes. You can change at most elements of the array . The changed values are at least and at most .
Take note that is not given in the input. In the description of the subtasks it is specified the value of depending on .
After the changes are made and the nodes are selected as specified in the above statement, let be the number of selected nodes .
You will be scored based on how large the number is.
Note: You are not required to find the maximum possible value of . You will get the points for a subtask if meets the condition specified in the subtask description.
Input data
The first line contains the number . The second line contains values, where the -th value represents the parent of node . The third line contains integers, representing the array . The last line contains integers, representing the array .
Output data
The first line contains the elements of the array after the changes, in order from to . The second line contains an integer , representing the number of nodes that satisfy the given condition. The following lines contains data about chosen nodes .
Each of these lines has the following format:
- The node which satisfies the condition.
- The chosen proper ancestor node .
- The size of the selected subset of nodes (can be ).
- The nodes in the subset (if any).
The values on the same line in the output are separated by a single space.
Constraints and clarifications
- The solution is not unique and you will be scored according to the subtasks description.
# | Points | Restrictions |
---|---|---|
1 | 12.5 | , , |
2 | 4 | , , |
3 | 8.5 | , , |
4 | 25 | , , |
5 | 12.5 | , , |
6 | 4 | , , |
7 | 8.5 | , , |
8 | 25 | , , |
Example
stdin
6
1 1 2 2 3
3 2 1 2 3 2
1 5 2 3 2 5
stdout
10 5 1 2 3 2
3
2 1 1 2
4 2 1 4
5 1 2 2 5
Explanation
In the array , changes were made for positions , , and .
The number of nodes that satisfy the condition after the changes is .
For example, one of the selected nodes is , and the subset has 1 node, . It can be observed that .
Another selected node is , and the subset has 2 nodes, . It can be observed that .