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

33768번 - Ski Slope 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
2 초 2048 MB80453757.812%

문제

Bessie is going on a ski trip with her friends. The mountain has $N$ waypoints (1ドル\leq N \leq 10^5$) labeled 1,ドル 2, \ldots, N$ in increasing order of altitude (waypoint 1ドル$ is the bottom of the mountain).

For each waypoint $i > 1,ドル there is a ski run starting from waypoint $i$ and ending at waypoint $p_i$ (1ドル\le p_i<i$). This run has difficulty $d_i$ (0ドル \leq d_i \leq 10^9$) and enjoyment $e_i$ (0ドル \leq e_i \leq 10^9$).

Each of Bessie's $M$ friends (1ドル\leq M \leq 10^5$) will do the following: They will pick some initial waypoint $i$ to start at, and then follow the runs downward (to $p_i,ドル then to $p_{p_i},ドル and so forth) until they get to waypoint 1ドル$.

The enjoyment each friend gets is equal to the sum of the enjoyments of the runs they follow. Each friend also has a different skill level $s_j$ (0ドル \leq s_j \leq 10^9$) and courage level $c_j$ (0ドル \leq c_j \leq 10$), which limits them to selecting an initial waypoint that results in them taking at most $c_j$ runs with difficulty greater than $s_j$.

For each friend, compute the maximum enjoyment they can get.

입력

The first line contains $N$.

Then for each $i$ from 2ドル$ to $N,ドル a line follows containing three space-separated integers $p_i,ドル $d_i,ドル and $e_i$.

The next line contains $M$.

The next $M$ lines each contain two space-separated integers $s_j$ and $c_j$.

출력

Output $M$ lines, with the answer for each friend on a separate line.

Note that the large size of integers involved in this problem may require the use of 64-bit integer data types (e.g., a "long long" in C/C++).

제한

예제 입력 1

4
1 20 200
2 30 300
2 10 100
8
19 0
19 1
19 2
20 0
20 1
20 2
29 0
30 0

예제 출력 1

0
300
500
300
500
500
300
500
  1. The first friend cannot start any waypoint other than 1ドル,ドル since any other waypoint would cause them to take at least one run with difficulty greater than 19ドル$. Their total enjoyment is 0ドル$.
  2. The second friend can start at waypoint 4ドル$ and take runs down to waypoint 2ドル$ and then 1ドル$. Their total enjoyment is 100ドル+200=300$. They take one run with difficulty greater than 19ドル$.
  3. The third friend can start at waypoint 3ドル$ and take runs down to waypoint 2ドル$ and then 1ドル$. Their total enjoyment is 300ドル+200=500$. They take two runs with difficulty greater than 19ドル$.

힌트

출처

Olympiad > USA Computing Olympiad > 2024-2025 Season > USACO 2025 US Open Contest > Silver 3번

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

출처

대학교 대회

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

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