22832023-01-09 12:45:51bzsofiaLogisztikai központcpp11Futási hiba 27/5037ms14080 KiB
// Logisztikai kozpont.cpp : This file contains the 'main' function. Program execution begins and ends there.
//

#include <iostream>
#include <vector>
#include <queue>

using namespace std;

long long a, b, c, i, n, kezd, akt, maxt, mint = 9999999999999999, ido[1001][1001];
queue <long long> s;
vector <long long> mini;

struct adat
{
    long long tav;
    bool lat;
    vector <long long> sz;
};

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    cin >> n;
    vector <adat> x(n + 1);
    //vector <vector<long long>> ido(n + 1, vector <long long>(n + 1));
    for (i = 1; i < n; ++i)
    {
        cin >> a >> b >> c;
        ido[a][b] = ido[b][a] = c;

        x[a].sz.push_back(b);
        x[b].sz.push_back(a);
    }

    for (kezd = 1; kezd <= n; ++kezd)
    {
        for (i = 1; i <= n; ++i)
        {
            x[i].lat = 0;
            x[i].tav = 0;
        }

        x[kezd].lat = 1;
        s.push(kezd);
        while (!s.empty())
        {
            akt = s.front();
            s.pop();
            for (auto& e : x[akt].sz)
            {
                if (!x[e].lat)
                {
                    x[e].lat = 1;
                    x[e].tav = x[akt].tav + ido[akt][e];
                    s.push(e);
                }
            }
        }

        maxt = 0;
        for (i = 1; i <= n; ++i)
        {
            if (x[i].tav > maxt)
            {
                maxt = x[i].tav;
            }
        }

        if (maxt < mint)
        {
            mint = maxt;
            mini.clear();
            mini.push_back(kezd);
        }
        else if (maxt == mint) mini.push_back(kezd);
    }

    cout << mint << "\n" << mini.size() << "\n";
    for (auto& e : mini) cout << e << " ";

    return 0;
}

// Run program: Ctrl + F5 or Debug > Start Without Debugging menu
// Debug program: F5 or Debug > Start Debugging menu

// Tips for Getting Started: 
//   1. Use the Solution Explorer window to add/manage files
//   2. Use the Team Explorer window to connect to source control
//   3. Use the Output window to see build output and other messages
//   4. Use the Error List window to view errors
//   5. Go to Project > Add New Item to create new code files, or Project > Add Existing Item to add existing code files to the project
//   6. In the future, to open this project again, go to File > Open > Project and select the .sln file
RészfeladatÖsszpontTesztVerdiktIdőMemória
base27/50
1Elfogadva0/03ms2008 KiB
2Futási hiba0/04ms9340 KiB
3Elfogadva4/42ms2500 KiB
4Elfogadva4/42ms2784 KiB
5Elfogadva4/42ms3348 KiB
6Elfogadva4/42ms3400 KiB
7Elfogadva4/43ms4492 KiB
8Elfogadva5/537ms14080 KiB
9Futási hiba0/24ms11248 KiB
10Futási hiba0/24ms11212 KiB
11Elfogadva2/28ms8568 KiB
12Futási hiba0/22ms3608 KiB
13Futási hiba0/22ms3884 KiB
14Futási hiba0/22ms4332 KiB
15Futási hiba0/24ms10872 KiB
16Futási hiba0/24ms10760 KiB
17Futási hiba0/24ms11368 KiB
18Futási hiba0/24ms9712 KiB
19Futási hiba0/26ms12216 KiB
20Futási hiba0/34ms12160 KiB