Logo
(追記) (追記ここまで)

26403번 - Big Numbers 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
2 초 (추가 시간 없음) 1024 MB311100.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:

  1. Traverse $p$-$v$ edge (the edge from $p$ to $v$).
  2. Make a trip from $v$.
  3. Teleport from vertex $v$ to vertex $p$ without traversing any edges.

A trip from vertex $v$ is the following procedure:

  1. Make a journey to all of the children of $v$ (if any).
  2. If $v$ has at least one child, make a journey to some child of $v$ one more time.

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円$.

제한

예제 입력 1

7
1 1
2 1
1 4
2 2
1 2
5 0

예제 출력 1

52

예제 입력 2

3
1 28
1 1000000000000000000

예제 출력 2

752834992

힌트

출처

Camp > Moscow Pre-Finals ACM ICPC Workshop > Moscow Pre-Finals ACM ICPC Workshop 2018 B번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /