This problem is the Critical Path Method, a technique used in project management to find the minimum time to complete a project with dependencies. You can take multiple courses in parallel, but each course can only start after all its prerequisites are finished.
The finish time of course is: finish[i] = time[i] + max(finish[j]) for all prerequisites of . If course has no prerequisites, finish[i] = time[i]. The answer is max(finish[i]) over all courses.
Why topological sort? We need to compute finish[j] before finish[i] for all prerequisites . Processing in topological order guarantees this. The longest path in the dependency graph is the critical path. It determines the minimum project duration.