43982023-03-27 13:30:33vááááLegtávolabbi leszármazottcsharpRuntime error 46/50286ms74344 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+9];
            int w, u;
            string[] v = new string[2];
            for (int i = 0; i < n+9; i++)
            {
                a[i] = new List<int>();
            }
            List<int> fel = new List<int>();
            List<int> le = new List<int>();
            for (int i = 0; i < n; i++)
            {
                v = Console.ReadLine().Split();
                w = int.Parse(v[0]);
                u = int.Parse(v[1]);
                fel.Add(w);
                le.Add(u);
                a[w].Add(u);
            }
            fel = fel.Except(le).ToList();
            bejar(fel[0], 0);
            /**
            while (le.Count != 0)
            {
                fel.Clear();
                fel.AddRange(le);
                le.Clear();
                for (int i = 0; i < fel.Count; i++)
                {
                    le.AddRange(a[fel[i]]);
                }
            }
            Console.WriteLine(fel[0]);  **/
            Console.WriteLine(maxpont);
            Console.ReadKey();
            /**
8
1 4
5 7
8 6
8 5
3 1
3 2
3 8
            **/
        }
    }
}
SubtaskSumTestVerdictTimeMemory
base46/50
1Accepted0/034ms21696 KiB
2Accepted0/0245ms57220 KiB
3Accepted1/134ms22736 KiB
4Accepted3/332ms22936 KiB
5Accepted3/332ms23284 KiB
6Accepted1/132ms22964 KiB
7Accepted1/132ms23252 KiB
8Accepted1/135ms24000 KiB
9Accepted2/2259ms60604 KiB
10Accepted3/3261ms60788 KiB
11Accepted3/335ms24124 KiB
12Accepted4/4277ms71648 KiB
13Accepted4/4286ms71460 KiB
14Accepted3/356ms31824 KiB
15Accepted3/3277ms70448 KiB
16Accepted3/3254ms71448 KiB
17Accepted3/3250ms70948 KiB
18Accepted4/4209ms62412 KiB
19Accepted4/4225ms69388 KiB
20Runtime error0/4261ms74344 KiB