| 시간 제한 | 메모리 제한 | 제출 | 정답 | 맞힌 사람 | 정답 비율 |
|---|---|---|---|---|---|
| 2 초 (추가 시간 없음) | 1024 MB | 3 | 1 | 1 | 100.000% |
Problems with big numbers taken modulo some small number discriminate Python. ©Some blue guy on Codeforces.
You are given a directed rooted tree. All edges are directed away from the root. Each edge has length which is a power of 2. The root of the tree has number 1.
Let's define two terms, which will depend on each other --- a trip from vertex $v,ドル and a journey to vertex $v$.
A journey to some vertex $v$ always starts from its parent $p$ (it means that a journey to the root of the tree may never occur) and consists of three steps:
A trip from vertex $v$ is the following procedure:
Note that any trip or journey always starts and ends at the same vertex.
Length of the trip is the total length of all traversed edges with multiplicity during the trip.
What is the maximum length of a trip from the root? Calculate it modulo 998ドル,244円,353円$.
The first line of input contains a single integer $n$ (2ドル \leq n \leq 10^5$), the number of vertices in the tree.
Next $n - 1$ lines describe the tree. $i$-th of these lines contains two integers $p_i$ and $c_i$ (1ドル \leq p_i \leq i, 0 \leq c_i \leq 10^{18}$) describing an edge between vertices $p_i$ and $i+1$ with length 2ドル^{c_i}$.
Output a single integer, the maximum length of a trip from the root modulo 998ドル,244円,353円$.
7 1 1 2 1 1 4 2 2 1 2 5 0
52
3 1 28 1 1000000000000000000
752834992