아직 만들고 있는 페이지입니다.

이 페이지는 아직 만드는 중입니다. 보이는 내용은 바뀔 수 있습니다.

Big Numbers

시간 제한2초메모리 제한1024 MB

요약
각 간선 길이가 2의 거듭제곱인 루트 있는 트리에서 루트에서 시작하는 여행의 최대 길이를 998244353으로 나눈 나머지를 구한다.
난이도

보통10점 중 6점

유형
트리, DFS, 그리디, 수학
정답자
아직 제출이 없습니다

문제

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 vv, and a journey to vertex vv.

A journey to some vertex vv always starts from its parent pp (it means that a journey to the root of the tree may never occur) and consists of three steps:

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

A trip from vertex vv is the following procedure:

  1. Make a journey to all of the children of vv (if any).
  2. If vv has at least one child, make a journey to some child of vv 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,353998\\,244\\,353.

입력

The first line of input contains a single integer nn (2≤n≤1052 \leq n \leq 10^5), the number of vertices in the tree.

Next n−1n - 1 lines describe the tree. ii-th of these lines contains two integers p_ip\_i and c_ic\_i (1≤p_i≤i,0≤c_i≤10181 \leq p\_i \leq i, 0 \leq c\_i \leq 10^{18}) describing an edge between vertices p_ip\_i and i+1i+1 with length 2c_i2^{c\_i}.

출력

Output a single integer, the maximum length of a trip from the root modulo 998,244,353998\\,244\\,353.

예제2

  1. 예제 1

    입력
    7
    1 1
    2 1
    1 4
    2 2
    1 2
    5 0
    
    예상 출력
    52
    
  2. 예제 2

    입력
    3
    1 28
    1 1000000000000000000
    
    예상 출력
    752834992