若图为有向无环图,则可进行拓扑排序。拓扑排序的结果为DFS后序遍历的倒序。选课是拓扑排序的经典应用场景之一,即:选修一门课程之前须先修完该课程的前置课程。 class Graph(object): def __init__(self, points_nums, is_directed): self.__points_nums = points_nums self.__adj = [[] for _ in range(points_nums)] self.__directed = is_directed self.__in_