using System; using System.Collections.Generic; using System.Linq; public class Node { public int id; public Node next; public int indegree = 0; public bool visited = false; } public class Test { public static void Main() { // read number of nodes of the graph int n = Convert.ToInt32(Console.ReadLine()); Node []nodes = new Node[n]; // initiate nodes for (int i=0;i>(); var count = 0; for (int i=0;i()); var current = nodes[i]; while (!current.visited) { cycles[count].Add(current.id); nodes[current.id].visited = true; current = current.next; } count++; } } // Print cycles and find largest cycle and its length if (cycles.Count > 0) { Console.WriteLine("All cycles:"); for (int i=0;ix.Count); Console.WriteLine("Maximum cycle length is: " + maxLength); Console.WriteLine("Largest cycle is: " + String.Join(", ",cycles.FirstOrDefault( x=>x.Count==maxLength))); } else Console.WriteLine("There is no cycle in the graph"); } }