RiseOJ는 solved.ac와 제휴 관계가 없습니다. 티어 아이콘 © solved.ac. solved.ac
포럼
문제 COCI00727

Skijanje

설명

Skier Mia spent a day at an unusual ski resort. The resort consists of \(n\) apres-ski
locations (hereafter: apres) connected by slopes such that they form a connected
tree rooted at the apres labeled 1. Each slope is directed from the apres with a
smaller number to the apres with a larger number.
The tree is defined as follows: for each apres \(i > 1\), it is known from which apres
\(p_{i}\) (\(p_{i} < i\)) one arrives at it, i.e., its parent in the tree is known. This uniquely
determines all slopes (slope \(i\) leads to the apres labeled \(i\)).
During the day, Mia skied each slope exactly once and for each slope remembered its fun factor \(z_{i}\) and
speed \(b_{i}\).
At the end of the day, Mia wants to ski down once more. Since Mia is very tired from skiing all day,
she will choose a run consisting of at most \(k\) consecutive slopes. The run must follow the direction of
the slopes (from apres with smaller numbers to those with larger numbers). After finishing the run, a
helicopter will pick her up and take her home.
For any chosen run, we define its hecticness as follows. Let:
\(z_{first}\) be the fun factor of the first slope in the run
\(z_{last}\) be the fun factor of the last slope in the run
\(b_{i}\) be the speeds of all slopes in that run
Then the hecticness of the run is: \(z_{last}\) · (\(z_{last}\) + ^{P} \(b_{i}\)) + \(z^{2}\)
_{first}^{.} ^{In} ^{the} ^{case} ^{k} ^{=} ^{1,} ^{the} ^{formula} ^{remains}
unchanged, and fir\(st = la\)st holds.
Your task is to determine the maximum hecticness of a run that Mia can ski.

제약
입력 형식

The first line contains natural numbers n, k (\(1 \le k \le n \le 3 \cdot 10^{5}\)), as described in the problem statement.
The second line contains \(n - 1\) integers, where the \(i\)-th number represents from which apres one can reach
the apres labeled \(i + 1\) (\(1 \le p_{i} \le i\)).
The third line contains \(n - 1\) integers, where the \(i\)-th number represents the fun factor of the (\(i + 1\))-th
slope (\(1 \le z_{i} \le 10^{5}\)).
The fourth line contains \(n - 1\) integers, where the \(i\)-th number represents the speed of the (\(i + 1\))-th slope
(−\(10^{5} \le b_{i} \le 10^{5}\)).

출력 형식

In the first and only line, output a single number - the maximum hecticness of a run that Mia can ski.

서브태스크
서브태스크점수설명

1

14점

\(n \le 1000\)

2

23점

For each \(1 \le i < n\) it will hold that \(z_{i} = 1\) and \(b_{i} > 1\).

3

35점

\(n \le 50000\)

4

38점

No additional constraints.

예제 1
입력
5 1
1 2 2 1
5 4 8 7
6 3 9 3
출력
200
예제 2
입력
9 2
1 2 1 1 4 3 6 5
1 3 7 8 4 1 8 2
1 -7 -1 -6 3 8 -1 6
출력
120
설명

Clarification of the first example: Since k = 1, it follows that the maximum hecticness of a run
is equal to the maximum hecticness among the individual slopes. The slopes have hecticness values of
80, 44, 200, and119. The maximum hecticness is 200.

문제 정보

생성자가 기록되지 않았습니다.

출처 COCI 2025/2026 Contest 6

평가 및 의견

Skijanje

개요
출제자 난이도 Unrated 레이팅 미적용 의견 0 / 50 공개 집계 (커뮤니티 난이도, 주요 주제, 품질)는 의견이 충분히 모이면 공개됩니다.

Log in to rate problems.

개별 의견

아직 의견이 없습니다. 자격이 된다면 위 양식에서 가장 먼저 평가해 보세요.

풀이 제출

Skijanje

게스트로 둘러보고 있습니다. 로그인하면 풀이를 제출하고 진행 상황을 확인할 수 있습니다. 로그인하고 제출하기
공개
C++20 Tab 들여쓰기 · Ctrl+/ 주석 토글 · Enter 자동 들여쓰기
1 1 1 0 공백: 4 · UTF-8