Deadlock Detection — Solution & Editorial
Kahn's algorithm: repeatedly remove in-degree-0 nodes; if fewer than N get removed, the remainder forms a cycle. (DFS with colors is the classic alternative.)
Complexity: O(N + M)
Kahn's algorithm: repeatedly remove in-degree-0 nodes; if fewer than N get removed, the remainder forms a cycle. (DFS with colors is the classic alternative.)
Complexity: O(N + M)