classSolution: defcanFinish(self, numCourses: int, prerequisites: List[List[int]]) -> bool: indegrees = [0for _ in range(numCourses)] adjacency = [[] for _ in range(numCourses)] queue = deque() # Get the indegree and adjacency of every course. for cur, pre in prerequisites: indegrees[cur] += 1 adjacency[pre].append(cur) # Get all the courses with the indegree of 0. for i in range(len(indegrees)): ifnot indegrees[i]: queue.append(i) # BFS TopSort. while queue: pre = queue.popleft() numCourses -= 1 for cur in adjacency[pre]: indegrees[cur] -= 1 ifnot indegrees[cur]: queue.append(cur) returnnot numCourses