{"problem":{"name":"D. Gold paint optimization","description":{"content":"See PDF statement in attachment. ","description_type":"Markdown"},"platform":"Codeforces","limit":{"time_limit":10000,"memory_limit":262144},"difficulty":"None","is_remote":true,"is_sync":true,"sync_url":null,"sign":"CF10179D"},"statements":[{"statement_type":"Markdown","content":"See PDF statement in attachment.\n\n[samples]","is_translate":false,"language":"English"},{"statement_type":"Markdown","content":"**Definitions**  \nLet $ n \\in \\mathbb{Z}^+ $ be the number of nodes.  \nLet $ P = (p_1, p_2, \\dots, p_n) $ be the parent array, where $ p_i \\in \\{0, 1, \\dots, i-1\\} $, and $ p_i = 0 $ indicates node $ i $ is a root.  \nLet $ T = (V, E) $ be the rooted forest with $ V = \\{1, 2, \\dots, n\\} $ and $ E = \\{ (p_i, i) \\mid p_i \\neq 0 \\} $.  \n\n**Constraints**  \n1. $ 1 \\leq n \\leq 10^5 $  \n2. $ 0 \\leq p_i < i $ for all $ i \\in \\{1, \\dots, n\\} $  \n\n**Objective**  \nFind a permutation $ A = (a_1, a_2, \\dots, a_n) $ of $ \\{1, 2, \\dots, n\\} $ such that, when the method from the previous problem is applied to $ A $, the resulting forest (in terms of parent-child structure) is isomorphic to $ T $ under node relabeling.  \n\nThe method (from previous problem):  \n- Nodes are processed in order $ 1 $ to $ n $.  \n- Each node $ i $ is attached as a child to the *rightmost* previously processed node with value *greater than* $ a_i $.  \n- If no such node exists, it becomes a root.  \n\n**Goal**: Construct $ A $ such that the *tree structure* induced by this rule is isomorphic to $ T $.","is_translate":false,"language":"Formal"}],"meta":{"iden":"CF10179D","tags":[],"sample_group":[],"created_at":"2026-03-03 11:00:39"}}