Graph Cycle Detection Algorithm in C#