Optimal Algorithmic Approach
Kahn's BFS: track in-degrees, process zero-in-degree nodes, check count at end.
Core Invariants & Edge Cases
- Model as directed graph; a cycle means impossible
- Kahn's algorithm (BFS + in-degree) or DFS with 3-color marking
- If topological sort includes all nodes, no cycle exists