#P7124. [Ynoi2008] stcm
[Ynoi2008] stcm
Background
w33z is a conscientious problem setter.
Please use an efficient output method. This problem may require output up to 50 MB.
Problem Description
Given a tree, you can maintain a set that supports three operations:
- Insert a node into the current set.
- Undo the last insertion operation.
- Mark the current set as the "subtree complement information" of node .
The subtree complement information of a node is defined as the set obtained by removing all nodes in the subtree of (including itself) from the set of all nodes in the tree.
You must ensure that the subtree complement information for every node is correct.
Input Format
This problem contains multiple test cases.
For each test case:
The first line contains a positive integer .
The next line contains positive integers. The -th number indicates that the parent of node is node , and it is guaranteed that .
Read until EOF.
Output Format
For each test case, output a string. From left to right:
- Each substring of the form "+x" represents performing operation 1 on the node with index .
- Each substring "-" represents performing operation 2.
- Each substring of the form "=x" represents performing operation 3 on the node with index .
- Each substring "!" indicates that all operations have ended. Any input after it will be ignored. The string must end with "!".
No whitespace characters are allowed as separators in the output string.
6
1 1 2 3 3
6
1 1 2 3 3
=1+1+3+5+6=2+2=4----+4+2=3+3+6=5-+5=6!
=1+1+3+5+6=2+2=4----+4+2=3+3+6=5-+5=6!
Hint
Idea: nzhtl1477, Solution: ccz181078, Code: ccz181078, Data: ccz181078&nzhtl1477.
For of the testdata, , .
This problem uses Special Judge.
The allowed number of operation 1 is . You are not allowed to insert an element that already exists in the current set.
When there is no last insertion operation that has not been undone, operation 2 is not allowed.
For each node, you must perform operation 3 exactly once on it.
The outputs of all test cases are checked independently.
Translated by ChatGPT 5