using System.Collections.Generic;
public static int CountParties(int[] p)
var employees = new List<Employee>();
for (int i = 0; i < p.Length; i++)
employees.Add(new Employee());
Employee root = new Employee();
for (int i = 0; i < p.Length; i++)
root.AddSubordinate(employees[i]);
employees[p[i] - 1].AddSubordinate(employees[i]);
return root.GetHeight() - 1;
public static void Main(string[] args)
int[] p = [-1, 1, 1, 2, 3, -1];
Console.WriteLine(CountParties(p));
Console.WriteLine(CountParties(p1));
public List<Employee> subordinates;
subordinates = new List<Employee>();
public void AddSubordinate(Employee employee)
subordinates.Add(employee);
foreach (var subordinate in subordinates)
int height = subordinate.GetHeight();