(
node,
graph,
color,
topologicalOrder,
isDirectedAcyclicGraph,
)
| 83 | }; |
| 84 | |
| 85 | var checkNeighbors = ( |
| 86 | node, |
| 87 | graph, |
| 88 | color, |
| 89 | topologicalOrder, |
| 90 | isDirectedAcyclicGraph, |
| 91 | ) => { |
| 92 | for (const neighbor of graph[node]) { |
| 93 | const isNew = color[neighbor] === 1; // White |
| 94 | if (isNew) |
| 95 | dfs( |
| 96 | neighbor, |
| 97 | graph, |
| 98 | color, |
| 99 | topologicalOrder, |
| 100 | isDirectedAcyclicGraph, |
| 101 | ); |
| 102 | |
| 103 | const isCycle = color[neighbor] === 2; // Grey |
| 104 | if (isCycle) isDirectedAcyclicGraph[0] = false; |
| 105 | } |
| 106 | }; |
| 107 | |
| 108 | /** |
| 109 | * https://leetcode.com/problems/course-schedule-ii/ |
no test coverage detected