namespace NodePipeline.Engine.Graph; public static class CycleDetector { public static bool HasCycle(Dictionary> graph) { var visited = new HashSet(); var inStack = new HashSet(); foreach (var node in graph.Keys) if (Dfs(node)) return true; return false; bool Dfs(string current) { if (inStack.Contains(current)) return true; if (!visited.Add(current)) return false; inStack.Add(current); foreach (var next in graph[current]) if (Dfs(next)) return true; inStack.Remove(current); return false; } } }