Editorial for SAC '22 Code Challenge 5 Junior P4 - Course Requirements
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.
Submitting an official solution before solving the problem yourself is a bannable offence.
Author:
Subtask 1
It suffices to brute force through all possible permutations of courses and output any valid one.
Time Complexity:
Subtask 2
Realize that this problem is a classical topological sorting problem.
Maintain a queue for all the courses that have no prerequisites. Once a course has been satisfied, satisfy all the other courses that had this as a prerequisite, and, if that newly satisfied course does not have any other prerequisites, push it into the queue. Finally, output the order of courses in that queue.
Time Complexity:
Comments