| 시간 제한 | 메모리 제한 | 제출 | 정답 | 맞힌 사람 | 정답 비율 |
|---|---|---|---|---|---|
| 7 초 | 2048 MB | 24 | 10 | 9 | 47.368% |
Jimmy goes on an excursion in the country of Treenidad and Treebago. People there are obsessed with trees so much, they modeled their country after them. Being a careful planner, Jimmy wants to know in advance which cities should be visited to maximize the total appeal of his excursion. The appeal of a city is defined by a not necessarily positive integer. Since he went through a lot of hassle to get his visa, he wants to visit at least one city. Jimmy's excursion can start from any city. His only requirement when visiting the country is that he mustn't visit the same city twice.
The first line in the input contains an integer 1ドル\leq n \leq 10^6,ドル the number of cities in Treenidad and Treebago.\\ After that, $n$ lines follow, the first of which describes the root of the tree.\\ Each of the following lines contains two integers, $V$ and $C,ドル which describe the properties of a node in the tree:
After that, $C$ lines follow, each recursively defining the child trees. It is guaranteed that the height of the tree is less than or equal to 990ドル$.
The maximum appeal Jimmy can gather in his excursion.
5 5 2 2 2 1 0 10 0 -1 0
17
Figure E.1: Illustration of the first sample test case
7 1 3 3 2 5 0 6 0 2 1 3 0 4 0
15
Figure E.2: Illustration of the second sample test case