Build adjacency lists, detect cycles with DFS, and find valid course orderings
Haven't done Part 1? Start with DFS grid exploration first
Watch DFS cycle detection step-by-step with adjacency lists
Convert an edge list into an adjacency list for a directed graph.
Build an adjacency list and return the direct neighbors of a given node.
Count how many nodes in the graph have no outgoing edges.
Count how many edges point into each node in a directed graph.
Find and return one valid path from a start node to an end node using DFS.
Detect cycles in a prerequisite graph using DFS with three-color marking.
Find a valid course order using topological sort (DFS or Kahn's algorithm).