22852023-01-09 12:48:20bzsofiaLogisztikai központcpp11Futási hiba 0/503ms3784 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[10001][10001];
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
base0/50
1Futási hiba0/03ms1264 KiB
2Futási hiba0/02ms1324 KiB
3Futási hiba0/42ms1680 KiB
4Futási hiba0/42ms1680 KiB
5Futási hiba0/42ms2008 KiB
6Futási hiba0/42ms2204 KiB
7Futási hiba0/42ms2448 KiB
8Futási hiba0/52ms2544 KiB
9Futási hiba0/22ms2640 KiB
10Futási hiba0/22ms2720 KiB
11Futási hiba0/22ms2796 KiB
12Futási hiba0/22ms2992 KiB
13Futási hiba0/22ms3012 KiB
14Futási hiba0/22ms3200 KiB
15Futási hiba0/22ms3216 KiB
16Futási hiba0/22ms3400 KiB
17Futási hiba0/22ms3404 KiB
18Futási hiba0/22ms3588 KiB
19Futási hiba0/22ms3784 KiB
20Futási hiba0/32ms3572 KiB