MediumRating 1656
207. Course Schedule
depth-first-searchbreadth-first-searchgraphtopological-sort
解題說明
C++ 解法
複雜度分析
虛擬碼
1. Build adjacency list from prerequisites 2. Initialize state[0..n-1] = 0 (unvisited) 3. For each node i: a. Run DFS: if state[i]==1 → cycle; if state[i]==2 → skip b. Mark state[i]=1 (visiting), recurse on neighbors, mark state[i]=2 4. Return true if no cycle found