using System.Collections.Generic;
public static void Delete(List<int> Parent, ref int n, int u)
if(u == n) { n = n - 1; return; }
for (int i = 1; i <= n; i++)
if (Parent[i] == u) Parent[i] = Parent[u];
for (int i = 1; i <= n; i++)
if (Parent[i] == n) Parent[i] = u;
public static void Main()
n = int.Parse(Console.ReadLine());
List<int> Parents = new List<int>(n + 1);
for (m = 0; m <= n; m++) Parents.Add(0);
Console.WriteLine("ребро " + m);
u = int.Parse(Console.ReadLine());
v = int.Parse(Console.ReadLine());
Console.WriteLine("Списък на родителите\nребро: родител ");
{ Console.WriteLine("{0}: {1}", m, Parents[m]); }
Console.Write("\nИзтрийте връх \nk=");
int k = int.Parse(Console.ReadLine());
Delete(Parents, ref n, k);
Console.WriteLine("\nНомерът на връх "+(n+1) +" бе променен на "+k);
Console.WriteLine("\nСписък на родителите на новото дърво\nребро: родител ");
{ Console.WriteLine("{0}: {1}", m, Parents[m]); }