Upload code_segments/segment_383.txt with huggingface_hub
Browse files
code_segments/segment_383.txt
ADDED
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
This is an interactive problem.
|
2 |
+
|
3 |
+
Upon clearing the Waterside Area, Gretel has found a monster named Genokraken, and she's keeping it contained for her scientific studies.
|
4 |
+
|
5 |
+
The monster's nerve system can be structured as a tree$^{\dagger}$ of $n$ nodes (really, everything should stop resembling trees all the time$\ldots$), numbered from $0$ to $n-1$, with node $0$ as the root.
|
6 |
+
|
7 |
+
Gretel's objective is to learn the exact structure of the monster's nerve system — more specifically, she wants to know the values $p_1, p_2, \ldots, p_{n-1}$ of the tree, where $p_i$ ($0 \le p_i < i$) is the direct parent node of node $i$ ($1 \le i \le n - 1$).
|
8 |
+
|
9 |
+
She doesn't know exactly how the nodes are placed, but she knows a few convenient facts:
|
10 |
+
|
11 |
+
* If we remove root node $0$ and all adjacent edges, this tree will turn into a forest consisting of only paths$^{\ddagger}$. Each node that was initially adjacent to the node $0$ will be the end of some path. * The nodes are indexed in a way that if $1 \le x \le y \le n - 1$, then $p_x \le p_y$. * Node $1$ has exactly two adjacent nodes (including the node $0$).
|
12 |
+
|
13 |
+
| |  ---|---|--- The tree in this picture does not satisfy the condition, because if we remove node $0$, then node $2$ (which was initially adjacent to the node $0$) will not be the end of the path $4-2-5$.| The tree in this picture does not satisfy the condition, because $p_3 \le p_4$ must hold.| The tree in this picture does not satisfy the condition, because node $1$ has only one adjacent node. Gretel can make queries to the containment cell:
|
14 |
+
|
15 |
+
* "? a b" ($1 \le a, b < n$, $a \ne b$) — the cell will check if the simple path between nodes $a$ and $b$ contains the node $0$.
|
16 |
+
|
17 |
+
However, to avoid unexpected consequences by overstimulating the creature, Gretel wants to query at most $2n - 6$ times. Though Gretel is gifted, she can't do everything all at once, so can
|