D. Data Structure Master and Orz Pandas

Codeforces
IDCF10287D
Time1000ms
Memory256MB
Difficulty
English · Original
Formal · Original
Master _wang9897_ is the First Data Structure Master in Xidian University. Today he is teaching some Orz Pandas to learn Link-Cut Tree (LCT). As a practice, _wang9897_ has given an interesting problem to the Orz Pandas. *Note that you don't need to know LCT to solve this problem.* Given a rooted tree with $n$ nodes whose root is numbered $1$. In LCT each node $u$ can be assigned one _preferred child_ $v$. Certainly $v$ must be a child of $u$. Initially there is no preferred child assigned to each node. Then $m$ "LCT access" operations are performed as follow. For each operation, a node $v$ is chosen from all nodes uniformly. The path from the root to $v$, $(v_1, v_2, \\\\cdots, v_k)$ is then found, where $v_1 = 1$, and $v_k = v$. For $i = 1, 2, \\\\cdots, k -1$, if $v_i$ is not assigned a preferred child, or it is assigned to a preferred child which is not $v_{i + 1}$, the preferred child of $v_i$ is reassigned to $v_{i + 1}$. Let $f (m)$ be the time of reassignments of preferred child in total. Master _wang9897_ want the Orz Pandas to calculate $$ \lim_{m\rightarrow\infty} \frac{f(m)}{m} $$ Please solve the problem so _wang9897_ can compare the Orz Pandas' answer to yours. There is only one test case in the input file. The first line contains a integer $n$, the size of the tree. The second line contains $n -1$ integers $p_2, p_3, \\\\cdots, p_(n -1)$. $p_i$ is the parent of the node $i$. It's guaranteed that $1 <= p_i <= n <= 10^5$. Output one line, containing an integer, the answer modulo $998244353$. For the sample, the answer is $1 \/ 2$, so $1 dot.op 2^(-1)$ should be outputed. ## Input There is only one test case in the input file.The first line contains a integer $n$, the size of the tree. The second line contains $n -1$ integers $p_2, p_3, \\\\cdots, p_{n -1}$. $p_i$ is the parent of the node $i$.It's guaranteed that $1 <= p_i <= n <= 10^5$. ## Output Output one line, containing an integer, the answer modulo $998244353$. [samples] ## Note For the sample, the answer is $1 \/ 2$, so $1 dot.op 2^(-1)$ should be outputed.
**Definitions** Let $ n, m \in \mathbb{Z}^+ $ denote the dimensions of the grid. Let $ l, r \in \mathbb{Z} $ with $ 0 \le l \le r \le 8 $ define the survival range. Let $ t \in \mathbb{Z}^+ $ denote the number of time steps to evolve. Let $ G^{(0)} \in \{*, .\}^{n \times m} $ be the initial grid state (time step 1). For each time step $ k \in \{1, \dots, t\} $, let $ G^{(k)} $ denote the grid state at time $ k+1 $. **Transition Rule** For each cell $ (i, j) \in \{1, \dots, n\} \times \{1, \dots, m\} $, let $ N_{i,j}^{(k)} $ be the number of alive neighbors (Moore neighborhood, 8-directional) in $ G^{(k)} $. Then: $$ G^{(k+1)}_{i,j} = \begin{cases} * & \text{if } G^{(k)}_{i,j} = * \text{ and } l \le N_{i,j}^{(k)} \le r, \\ * & \text{if } G^{(k)}_{i,j} = . \text{ and } l \le N_{i,j}^{(k)} \le r, \\ . & \text{otherwise}. \end{cases} $$ **Constraints** 1. $ 1 \le n, m \le 100 $ 2. $ 0 \le l \le r \le 8 $ 3. $ 1 \le t \le 10^3 $ **Objective** Compute $ G^{(t)} $, the grid state after $ t $ time steps, starting from $ G^{(0)} $.
API Response (JSON)
{
  "problem": {
    "name": "D. Data Structure Master and Orz Pandas",
    "description": {
      "content": "Master _wang9897_ is the First Data Structure Master in Xidian University. Today he is teaching some Orz Pandas to learn Link-Cut Tree (LCT). As a practice, _wang9897_ has given an interesting problem",
      "description_type": "Markdown"
    },
    "platform": "Codeforces",
    "limit": {
      "time_limit": 1000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "CF10287D"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "Master _wang9897_ is the First Data Structure Master in Xidian University. Today he is teaching some Orz Pandas to learn Link-Cut Tree (LCT). As a practice, _wang9897_ has given an interesting problem...",
      "is_translate": false,
      "language": "English"
    },
    {
      "statement_type": "Markdown",
      "content": "**Definitions**  \nLet $ n, m \\in \\mathbb{Z}^+ $ denote the dimensions of the grid.  \nLet $ l, r \\in \\mathbb{Z} $ with $ 0 \\le l \\le r \\le 8 $ define the survival range.  \nLet $ t \\in \\mathbb{Z}^+ $ de...",
      "is_translate": false,
      "language": "Formal"
    }
  ]
}
Full JSON Raw Segments