47812023-03-31 12:15:30vááááLogisztikai központcsharpTime limit exceeded 47/501.006s78944 KiB
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace logisztikai_kozpont
{
    class Program
    {
        static List<int>[] ut;
        static List<int>[] ido;
        static long  tmax=long.MinValue, tmost = 0, maxpont;
        static bool eloszor;
        static string maxut;
        static List<int> ki = new List<int>();
        static List<int> utak = new List<int>(), utmax = new List<int>();

        static void merre(int pont, long tav, int honnan)
        {
            if (ut[pont].Count==1 && !eloszor)
            {
                if(tav >  tmax)
                {
                    tmax = tav;
                    maxpont = pont;
                }
            }
            else
            {
                eloszor = false;
                for (int i = 0; i < ut[pont].Count; i++)
                {
                    if(ut[pont][i] != honnan) merre(ut[pont][i], tav + ido[pont][i], pont);
                }
            }
          
        }
        static void merre2(int pont, long tav, int honnan)
        {
            utak.Add(pont);
            if (ut[pont].Count == 1 && !eloszor)
            {
                if (tav > tmax)
                {
                    tmax = tav;
                    maxpont = pont;
                    utmax = new List<int>(utak);
                }
            }
            else
            {
                eloszor = false;
                for (int i = 0; i < ut[pont].Count; i++)
                {
                    if (ut[pont][i] != honnan) merre2(ut[pont][i], tav + ido[pont][i], pont);
                }
            }
            utak.Remove(pont);
        }
        static int tav(int a , int b)
        {
            int t = 0;
            for (int i = 0; i < ut[a].Count; i++)
            {
                if (ut[a][i] == b)
                {
                    t = ido[a][i];
                    break;
                }
            }
            return t;
        }
        static void vege(int pont, int honnan)
        {
            ki.Add(pont);
            for (int i = 0; i < ut[pont].Count; i++)
            {
                if (ido[pont][i] == 0 && ut[pont][i] != honnan)
                {
                    vege(ut[pont][i], pont);
                }
            }
        }
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine())+1;
            ut = new List<int>[n];
            ido = new List<int>[n];
            for (int i = 0; i < n; i++)
            {
                ut[i] = new List<int>();
                ido[i] = new List<int>();
            }
            string[] c = new string[3];
            for (int i = 1; i < n-1; i++)
            {
                c = Console.ReadLine().Split();
                ut[int.Parse(c[0])].Add(int.Parse(c[1]));
                ut[int.Parse(c[1])].Add(int.Parse(c[0]));
                ido[int.Parse(c[0])].Add(int.Parse(c[2]));
                ido[int.Parse(c[1])].Add(int.Parse(c[2]));
            }
            if (n == 2)
            {
                Console.WriteLine(0);
                Console.WriteLine(1);
                Console.WriteLine(1);
                Console.ReadKey();
            }
            else if (n == 3)
            {
                Console.WriteLine(c[2]);
                Console.WriteLine(2);
                Console.WriteLine(1 + " " + 2);
                Console.ReadKey();
            }
            else
            {
                eloszor = true;
                merre(1, 0, -1);
                long kezdpont = maxpont;
                tmax = -1;
                eloszor = true;
                merre2((int)kezdpont, 0, -1);
                int[] jopontok = utmax.ToArray();
                long elozo = 0;
                int[] johely = new int[2];
                johely[0] = -1;
                johely[1] = -1;
                long kist = -1;
                for (int i = 0; i < jopontok.Length - 1; i++)
                {

                    tmost += tav(jopontok[i], jopontok[i + 1]);
                    if (tmost >= tmax / 2)
                    {
                        if(tmost == tmax/2)
                        {
                            johely[0] = jopontok[i+1];
                            kist = tmost;
                            break;
                        }
                        else if(tmost-tmax/2 > Math.Abs(elozo - tmax / 2)) {
                            johely[0] = jopontok[i];
                            kist = tmax - elozo;
                            break;
                        }
                        else if (tmost - tmax / 2 < Math.Abs(elozo - tmax / 2))
                        {
                            johely[0] = jopontok[i + 1];
                            kist = tmost;
                            break;

                        }
                        else
                        {
                            johely[0] = jopontok[i];
                            johely[1] = jopontok[i+1];
                            kist = tmax - elozo;
                        }
                    }
                    elozo = tmost;
                }
                vege(johely[0], -1);
                if(johely[1] != -1)
                {
                    vege(johely[1], -1);
                }
                Console.WriteLine(kist);
                Console.WriteLine(ki.Count);
                ki.Sort();
                for (int i = 0; i < ki.Count; i++)
                {
                    Console.WriteLine(ki[i] + " ");
                }
                Console.ReadKey();
            }
        }
    }
}
SubtaskSumTestVerdictTimeMemory
base47/50
1Accepted0/032ms20552 KiB
2Accepted0/0474ms68640 KiB
3Accepted4/432ms21512 KiB
4Accepted4/434ms22072 KiB
5Accepted4/432ms22720 KiB
6Accepted4/432ms22588 KiB
7Accepted4/434ms22724 KiB
8Accepted5/535ms24044 KiB
9Accepted2/2532ms73816 KiB
10Accepted2/2606ms73984 KiB
11Accepted2/235ms23492 KiB
12Accepted2/243ms25388 KiB
13Accepted2/252ms29360 KiB
14Accepted2/274ms35904 KiB
15Accepted2/2551ms71428 KiB
16Accepted2/2462ms70184 KiB
17Accepted2/2569ms73044 KiB
18Accepted2/2395ms63004 KiB
19Accepted2/2527ms78944 KiB
20Time limit exceeded0/31.006s57568 KiB