relations
and record the in-degree of each node.step
to 0 and visited_count
to 0.step
.
b. For each node in the queue, increment visited_count
.
c. For each neighbor of the node, decrement its in-degree.
d. If a neighbor's in-degree reaches 0, add it to the next queue.
e. Update the queue with the next queue.visited_count
equals the total number of courses, return step
. Otherwise, return -1
.