Editorial for Dr. Anne Anderson Coding Contest 1 P6 - Designing An Academic Course Calendar


Remember to use this editorial only when stuck, and not to copy-paste code from it. Please be respectful to the problem author and editorialist.
Submitting an official solution before solving the problem yourself is a bannable offence.

Author: sugo

Subtask 1

Mark each course that is a prerequisite of a required course as required. Then, iterate, starting from required courses without any prerequisites.

Subtask 2

Perform a multi-source BFS starting from each course without prerequisites. Keep track of the indegree (number of incomplete prerequisites) of each course. Each time a course is reached in the BFS, subtract one from its indegree count. A course can only be taken next semester when its indegree count reaches zero.

Subtask 3

Mark each course that is a prerequisite of a required course as required. Then, perform the same BFS as in Subtask 2, including only required courses.


Comments


  • 4
    jackkieee  commented on Feb. 18, 2025, 2:35 p.m.

    I think this solution is like Topological sort