#P1113. [USACO02FEB] 杂务
[USACO02FEB] 杂务
Problem Description
Farmer John's family pitches in with the chores during milking, doing all the chores as quickly as possible. At FJ's house, some chores cannot be started until others have been completed, e.g., it is impossible to wash the cows until they are in the stalls.
Farmer John has a list of chores that must be completed. Each chore requires an integer time to complete and there may be other chores that must be completed before this chore is started. We will call these prerequisite chores. At least one chore has no prerequisite: the very first one, number 1. Farmer John's list of chores is nicely ordered, and chore can have only chores as prerequisites. Write a program that reads a list of chores from 1 to N with associated times and all perquisite chores. Now calculate the shortest time it will take to complete all N chores. Of course, chores that do not depend on each other can be performed simultaneously.
Input Format
-
Line : One integer, .
-
Lines : lines, each with several space-separated integers. Line contains chore ; line contains chore , and so on. Each line contains the chore index , the length of time to complete the chore, and the prerequisites (range , of course), the number of the prerequisites .
Output Format
A single line with an integer which is the least amount of time required to perform all the chores.
7
1 5 0
2 2 1 0
3 3 2 0
4 6 1 0
5 1 2 4 0
6 8 2 4 0
7 4 3 5 6 0
23
Hint
Hint
Here is one task schedule:
- Chore starts at time , ends at time .
- Chore starts at time , ends at time .
- Chore starts at time , ends at time .
- Chore starts at time , ends at time .
- Chore starts at time , ends at time .
- Chore starts at time , ends at time .
- Chore starts at time , ends at time .