47742023-03-31 12:03:51vááááLogisztikai központcsharpPartially correct 37/50685ms137984 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 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, string aktut)
        {
            if (ut[pont].Count == 1 && !eloszor)
            {
                if (tav > tmax)
                {
                    tmax = tav;
                    maxpont = pont;
                    maxut = aktut;
                }
            }
            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, aktut + " " + 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, "");
                maxut += " " + maxpont.ToString();
                maxut = maxut.Trim();
                int[] jopontok = maxut.Split().Select(int.Parse).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);
                for (int i = 0; i < ki.Count; i++)
                {
                    Console.WriteLine(ki[i] + " ");
                }
                Console.ReadKey();
            }
        }
    }
}
SubtaskSumTestVerdictTimeMemory
base37/50
1Accepted0/035ms22040 KiB
2Accepted0/0578ms69992 KiB
3Accepted4/435ms22580 KiB
4Partially correct2/435ms22996 KiB
5Accepted4/435ms22880 KiB
6Partially correct2/435ms23508 KiB
7Partially correct2/435ms23712 KiB
8Accepted5/543ms26700 KiB
9Accepted2/2685ms75604 KiB
10Accepted2/2654ms75624 KiB
11Partially correct1/237ms25284 KiB
12Partially correct1/245ms27404 KiB
13Accepted2/259ms33472 KiB
14Accepted2/282ms37412 KiB
15Accepted2/2586ms72956 KiB
16Partially correct1/2639ms70972 KiB
17Accepted2/2620ms74060 KiB
18Partially correct1/2419ms63404 KiB
19Accepted2/2532ms80164 KiB
20Runtime error0/3574ms137984 KiB