President Trump has once again taken matters into his own hands, this time, to “fix” the global economy by personally deleting every tariff policy ever made. Naturally, the policies are stored in a complicated nested folder system, because what’s more “simple” than thousands of trade files inside /root?
Your job is to simulate the behavior of the Unix command rm -r, recursively wiping out every folder and file in post-order traversal. Just make sure to print each deletion path — after all, he’ll probably want to tweet about how “tremendously efficient” his cleanup was.
The folder structure is represented as an n-ary tree, written as a nested list.
Each node is represented as:
[name, [child1, child2, child3, ...]]
That is,
You must recursively delete all nodes in post-order traversal, meaning all children are deleted before their parent node. For each deletion, output the full path of the node, starting from the root (prefixed with /).
The input consists of a single line containing a valid list representation of an n-ary tree.
The list uses the following format:
[name, [child1, child2, ...]]
Constraints:
NOTE:
You can use Python’s ast.literal_eval() to safely convert the string input into a list structure before processing.
For example:
import ast
tree = ast.literal_eval(input().strip())
Then you can recursively traverse the tree to perform the deletions.
Print the deletion order in post-order traversal.
Each line should be in the form:
where <full_path> is the absolute path to the node starting from /root.