private static void TestLCA() { LCA.Node root = new LCA.Node(); LCA.Node p = new LCA.Node(); LCA.Node q = new LCA.Node(); LCA.Node lca = LCA.GetLCA(root, p, q); }
private static void Main() { var verticesChildren = new List <int> [1000]; for (int i = 0; i < 1000; ++i) { verticesChildren[i] = new List <int>(); } var output = new StringBuilder(); int testCount = int.Parse(Console.ReadLine()); for (int t = 1; t <= testCount; ++t) { output.AppendLine($"Case {t}:"); int vertexCount = int.Parse(Console.ReadLine()); for (int id = 0; id < vertexCount; ++id) { int[] line = Array.ConvertAll(Console.ReadLine().Split(), int.Parse); var children = verticesChildren[id]; children.Clear(); for (int i = 1; i < line.Length; ++i) { children.Add(line[i] - 1); } } var solver = new LCA(vertexCount, verticesChildren); int queryCount = int.Parse(Console.ReadLine()); for (int q = 0; q < queryCount; ++q) { string[] line = Console.ReadLine().Split(); output.Append(solver.Solve( firstVertexID: int.Parse(line[0]) - 1, secondVertexID: int.Parse(line[1]) - 1) + 1); output.AppendLine(); } } Console.Write(output); }