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

Dispatching

설명

In a sect of ninja, ninjas are dispatched to a client, and they are rewarded according to their work.
In this sect, there is one ninja called the Master. Every ninja except the Master has one and only one boss.
In order to preserve the confidentiality and to encourage leadership, any instructions concerning their work are
always sent by a boss to his/her subordinates. It is forbidden to send instructions by other methods.
You are gathering a number of ninjas and dispatch them to a client. You have to pay salaries to dispatched
ninjas. For each ninja, the amount of salary for him/her is fixed. The total amount of salaries paid to them should
be within a budget. Moreover, in order to send instructions, you have to choose a ninja as a manager who can send
instructions to all dispatched ninjas. When instructions are sent, a ninja who is not dispatched may mediate the
transmission. The manager may or may not be dispatched. If the manager is not dispatched, he will not be paid.
You would like to maximize the satisfaction level of the client as much as possible within a budget. The sat-
isfaction level of the client is calculated as the product of the total number of dispatched ninjas and the leadership
level of the manager. For each ninja, his/her leadership level is fixed.
Task
Write a program that, given the boss Bi, the amount of salary Ci, the leadership level Li of each ninja i (1 ≦i ≦N),
and the budget for salaries M, outputs the maximum value of the satisfaction level of the client when the manager
and dispatched ninjas are chosen so that all the conditions are fulfilled.

제약

1 ≦N ≦100 000
The number of ninjas
1 ≦M ≦1 000 000 000
The budget for salaries
0 ≦Bi < i
The boss of each ninja
1 ≦Ci ≦M
The amount of salary of each ninja
1 ≦Li ≦1 000 000 000
The leadership level of each ninja

In test cases worth 30% of the full score, N ≦3 000.
Sample Input and Output
Sample Input 1
Sample Output 1
5 4
0 3 3
1 3 5
2 2 2
1 2 4
2 3 1
6
If we choose ninja 1 as a manager and ninja 3, 4 as dispatched ninjas, the total amount of salaries is 4 which
does not exceed the budget 4. Since the number of dispatched ninjas is 2 and the leadership level of the manager
is 3, the satisfaction level of the client is 6. This is the maximum value.

입력 형식

Read the following data from the standard input.
• The first line of input contains two space separated integers N, M, where N is the number of ninjas and M
is the budget.
• The following N lines describe the boss, salary, leadership level of each ninja. The (i + 1)-th line contains
three space separated integers Bi,Ci, Li, describing that the boss of ninja i is ninja Bi, the amount of his/her
salary is Ci, and his/her leadership level is Li. The ninja i is the Master if Bi = 0. Since the inequality
Bi < i is always satisfied, for each ninja, the number of his/her boss is always smaller than the number of
himself/herself.

출력 형식

Write the maximum value of the satisfaction level of the client to the standard output.

문제 정보

rip 작성

출처 APIO 2012

평가 및 의견

Dispatching

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

Log in to rate problems.

개별 의견

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

풀이 제출

Dispatching

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