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

24251번 - Miners 서브태스크다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
1.5 초 1024 MB102225.000%

문제

There is a vertical mine with $N$ chambers, where each chamber has exactly one vertical tunnel that goes into it (from some other chamber which is closer to the surface). Chamber number one is connected directly to the outside. Formally, the mine is a tree, rooted in vertex number one.

Every tunnel has some score associated with it (which depends on a lot of factors, but in this problem we’re given these scores directly). Unfortunately, sometimes going through a tunnel is risky, so these scores can also be negative.

Currently we have some number of miners in each chamber. We want to create a mining assignment, which should include some of the miners (possibly none), and assign to each of them a vertical path. A vertical path can only go deeper - that is if a miner is in some chamber, he can only go to chambers which are further away from the surface. More formally, from a vertex in the tree, we can only go to its children. We define the score of such a path, as the sum of the scores in the tunnels we passed through. Similarly, the score of the assignment is the sum of the scores of the paths in it (if no miner was assigned a path, we consider the score being 0).

However, we also have some additional constraints! We don’t want to have “crowded” chambers, that is, for each chamber we have a constraint on the maximal number of miners that can end their path there. The miners who weren’t assigned a path will just leave the mine and won’t be counted towards these constraints.

We’re interested in the largest score of some mining assignment. Given the structure of the mine, the initial number of miners in each chamber, and the maximal number of miners that can end in each chamber, you should write a program, which computes this value.

입력

From the first line of the standard input, your program should read a single integer $N$ - the number of chambers (we consider chamber 1 as being connected to the outside). The second line lines contains $s_1,ドル ⋯, $s_N$ - the initial number of miners for each chamber. The third line lines contains $e_1,ドル ⋯, $e_N$ - the maximal number of miners that can end in each chamber. Finally, the last $N - 1$ lines contain a description of the tunnel: the $i$th of these lines contains $p_{i+1}$ and $w_{i+1},ドル which means that there is a vertical tunnel from chamber number $p_{i+1}$ to chamber number $i + 1$ with a score of $w_{i+1}$.

출력

On a single line, your program should print the largest possible score of some mining assignment.

제한

  • 2ドル ≤ N ≤ 5 × 10^5$
  • 0ドル ≤ s_i, e_i ≤ 2000,ドル for all 1ドル ≤ i ≤ N$
  • 1ドル ≤ p_i < i,ドル for all 2ドル ≤ i ≤ N$
  • $|w_i| ≤ 2000,ドル for all 2ドル ≤ i ≤ N$

서브태스크

번호배점제한
16

$N ≤ 8$.

212

$N ≤ 100$.

314

$N ≤ 2000$.

418

$N ≤ 10^5,ドル The tree forms a line, that is, for each 2ドル ≤ u ≤ N$ its parent $p_u = u - 1$. Also, $s_u = e_u = 1$ for all 1ドル ≤ u ≤ N$.

54

$N ≤ 10^5,ドル The tree forms a line, that is, for each 2ドル ≤ u ≤ N$ its parent $p_u = u - 1$.

620

$N ≤ 10^5$.

726

$N ≤ 5 \times 10^5$.

예제 입력 1

5
5 1 0 0 0
100 1 1 2 4
1 6
1 1
2 2
2 -1

예제 출력 1

32

힌트

One possible solution is:

  1. 1 → 2 → 4 with a score of 8
  2. 1 → 2 → 4 with a score of 8
  3. 1 → 2 with a score of 6
  4. 1 → 2 → 5 with a score of 5
  5. 1 → 2 → 5 with a score of 5

출처

Olympiad > International Autumn Tournament in Informatics > 2021 > Group A (Seniors) 2번

채점 및 기타 정보

  • 예제는 채점하지 않는다.
(追記) (追記ここまで)

출처

대학교 대회

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

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