94382024-02-21 17:35:12AblablablaLogisztikai központcpp17Time limit exceeded 31/501.1s13164 KiB
#include <bits/stdc++.h>

using namespace std;

typedef pair<int, int> pii;

const int INF = 2e9 + 7;

vector<vector<pii>> csucsok;

int dfs(int akt, int elozo){
    int vissza = 0;

    for(pii x : csucsok[akt]){
        if(x.first == elozo) continue;

        vissza = max(vissza, dfs(x.first, akt) + x.second);
    }

    return vissza;
}

int main()
{
    int n;
    cin >> n;

    csucsok.assign(n, vector<pii>());
    for(int i = 0; i < n - 1; i++){
        int a, b, c;
        cin >> a >> b >> c;
        a--; b--;

        csucsok[a].push_back({b, c});
        csucsok[b].push_back({a, c});
    }

    int mini = INF;
    vector<int> minInd;
    for(int i = 0; i < n; i++){
        int a = dfs(i, -1);

        if(a < mini){
            mini = a;
            minInd.clear();
            minInd.push_back(i);
        } else if(a == mini){
            minInd.push_back(i);
        }
    }

    cout << mini << "\n";
    cout << minInd.size() << "\n";
    for(int x : minInd){
        cout << x + 1 << " ";
    }
    cout << "\n";
}
SubtaskSumTestVerdictTimeMemory
base31/50
1Accepted0/03ms1684 KiB
2Time limit exceeded0/01.1s6588 KiB
3Accepted4/43ms2128 KiB
4Accepted4/43ms2272 KiB
5Accepted4/43ms2520 KiB
6Accepted4/43ms2728 KiB
7Accepted4/43ms2788 KiB
8Accepted5/514ms3208 KiB
9Time limit exceeded0/21.1s8396 KiB
10Time limit exceeded0/21.065s8516 KiB
11Accepted2/24ms3512 KiB
12Accepted2/225ms3888 KiB
13Accepted2/2614ms4116 KiB
14Time limit exceeded0/21.057s3296 KiB
15Time limit exceeded0/21.077s8480 KiB
16Time limit exceeded0/21.062s8480 KiB
17Time limit exceeded0/21.046s8692 KiB
18Time limit exceeded0/21.039s7348 KiB
19Time limit exceeded0/21.065s9348 KiB
20Time limit exceeded0/31.042s13164 KiB