43992023-03-27 13:37:50vááááLegtávolabbi leszármazottcsharpRuntime error 46/50282ms74580 KiB
using System;
using System.Collections.Generic;
using System.Linq;

namespace legtavolabbi
{
    class Program
    {
        static List<int>[] a;
        static int maxszint = 0, maxpont=0;
        static void bejar(int aktpont, int szint)
        {
            if(a[aktpont].Count == 0)
            {
                if(szint > maxszint)
                {
                    maxszint = szint;
                    maxpont = aktpont;
                }
            }
            else
            {
                foreach (var item in a[aktpont])
                {
                    bejar(item, szint + 1);
                }
            }
        }
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine())-1;
            a = new List<int>[n+2];
            int w, u;
            string[] v = new string[2];
            HashSet<int> halmaz = new HashSet<int>();
            for (int i = 0; i < n+2; i++)
            {
                a[i] = new List<int>();
                halmaz.Add(i);
            }
            halmaz.Remove(0);
            for (int i = 0; i < n; i++)
            {
                v = Console.ReadLine().Split();
                w = int.Parse(v[0]);
                u = int.Parse(v[1]);
                halmaz.Remove(u);
                a[w].Add(u);
            }
            bejar(halmaz.ToArray()[0], 0);
            Console.WriteLine(maxpont);
            Console.ReadKey();
        }
    }
}
SubtaskSumTestVerdictTimeMemory
base46/50
1Accepted0/035ms23140 KiB
2Accepted0/0244ms55012 KiB
3Accepted1/134ms24020 KiB
4Accepted3/332ms24372 KiB
5Accepted3/334ms24804 KiB
6Accepted1/135ms24980 KiB
7Accepted1/134ms25404 KiB
8Accepted1/135ms26152 KiB
9Accepted2/2238ms59588 KiB
10Accepted3/3246ms59848 KiB
11Accepted3/335ms26880 KiB
12Accepted4/4273ms70600 KiB
13Accepted4/4282ms70480 KiB
14Accepted3/354ms33908 KiB
15Accepted3/3261ms69256 KiB
16Accepted3/3245ms70512 KiB
17Accepted3/3261ms69496 KiB
18Accepted4/4204ms57864 KiB
19Accepted4/4229ms67768 KiB
20Runtime error0/4279ms74580 KiB