Big Numbers
시간 제한2초메모리 제한1024 MB
각 간선 길이가 2의 거듭제곱인 루트 있는 트리에서 루트에서 시작하는 여행의 최대 길이를 998244353으로 나눈 나머지를 구한다.
문제
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 , and a journey to vertex .
A journey to some vertex always starts from its parent (it means that a journey to the root of the tree may never occur) and consists of three steps:
- Traverse - edge (the edge from to ).
- Make a trip from .
- Teleport from vertex to vertex without traversing any edges.
A trip from vertex is the following procedure:
- Make a journey to all of the children of (if any).
- If has at least one child, make a journey to some child of 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 .
입력
The first line of input contains a single integer (), the number of vertices in the tree.
Next lines describe the tree. -th of these lines contains two integers and () describing an edge between vertices and with length .
출력
Output a single integer, the maximum length of a trip from the root modulo .