22752023-01-09 08:50:34bzsofiaLogisztikai központcpp11Futási hiba 29/5065ms126844 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;

int a, b, c, i, n, kezd, akt, maxt, mint=999999999;
queue <int> s;
vector <int> mini;

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

int main()
{
    cin >> n;
    vector <adat> x(n + 1);
    vector <vector<int>> ido(n + 1, vector <int> (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
base29/50
1Elfogadva0/03ms1684 KiB
2Futási hiba0/043ms121200 KiB
3Elfogadva4/42ms1924 KiB
4Elfogadva4/42ms2204 KiB
5Elfogadva4/42ms2328 KiB
6Elfogadva4/42ms2348 KiB
7Elfogadva4/43ms2808 KiB
8Elfogadva5/535ms10760 KiB
9Futási hiba0/254ms121764 KiB
10Futási hiba0/243ms121732 KiB
11Elfogadva2/28ms5128 KiB
12Elfogadva2/265ms21060 KiB
13Futási hiba0/257ms126844 KiB
14Futási hiba0/256ms126552 KiB
15Futási hiba0/254ms122504 KiB
16Futási hiba0/245ms122704 KiB
17Futási hiba0/254ms122192 KiB
18Futási hiba0/246ms123712 KiB
19Futási hiba0/243ms122428 KiB
20Futási hiba0/354ms122484 KiB