86372024-01-24 12:14:53MagyarKendeSZLGLogisztikai központcpp17Időlimit túllépés 29/501.1s28468 KiB
#include <bits/stdc++.h>

#pragma region Utility

#define speed cin.tie(0); ios::sync_with_stdio(0)
#define cinv(v) for (auto& e : v) cin >> e;

#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define size(v) (int)v.size()
#define has(s, e) s.count(e)

#define max_index(v) max_element(all(v)) - v.begin()
#define min_index(v) min_element(all(v)) - v.begin()
#define smax(x, y) x = max(x, y)
#define smin(x, y) x = min(x, y)

#define sum(v) accumulate(all(v), 0)
#define product(v, T) accumulate(all(v), 1, multiplies<T>())

using namespace std;
using ll = long long;
using point = array<int, 2>;

int max(point p) { return max(p[0], p[1]); }
int min(point p) { return min(p[0], p[1]); }

template <typename T>
vector<T> prefix_sum(const vector<T>& v) {
    vector<T> result(size(v));
    partial_sum(all(v), result.begin());
    return result;
}

#pragma endregion

ll dijkstra(int s, const vector<vector<point>>& g) {
    int N = size(g) - 1;
    vector<ll> distS(N + 1, LLONG_MAX);
    priority_queue<pair<ll, int>, vector<pair<ll, int>>, greater<pair<ll, int>>> pq;
    ll result = 0;

    distS[0] = 0;
    distS[s] = 0;
    pq.push({0, s});

    while (!pq.empty()) {
        auto [dist, node] = pq.top(); pq.pop();

        if (distS[node] != dist) {
            continue;
        }

        for (auto [neigh, neigh_dist] : g[node]) {
            ll new_dist = dist + neigh_dist;


            if (new_dist < distS[neigh]) {
                distS[neigh] = new_dist;
                pq.push({new_dist, neigh});
            }
        }
    }

    return *max_element(all(distS));
}

int main() {
    #ifdef ONLINE_JUDGE
    speed;
    #else
    #define cin fin
    ifstream fin("input.txt");
    #endif

    int N;
    cin >> N;

    vector<vector<point>> g(N + 1);
    
    for (int i = 1; i < N; i++) {
        int u, v, w;
        cin >> u >> v >> w;
        g[u].push_back({v, w});
        g[v].push_back({u, w});
    }

    vector<ll> values(N + 1);

    for (int i = 1; i <= N; i++) {
        values[i] = dijkstra(i, g);
    }

    values[0] = LLONG_MAX;
    int mn = *min_element(all(values));

    cout << mn << '\n';

    vector<int> startS;

    for (int i = 1; i <= N; i++) {
        if (values[i] == mn) {
            startS.push_back(i);
        }
    }

    cout << size(startS) << '\n';
    for (int x : startS) cout << x << ' ';
}
RészfeladatÖsszpontTesztVerdiktIdőMemória
base29/50
1Elfogadva0/03ms1828 KiB
2Időlimit túllépés0/01.1s10368 KiB
3Elfogadva4/43ms3952 KiB
4Elfogadva4/43ms4064 KiB
5Elfogadva4/43ms4264 KiB
6Elfogadva4/43ms4484 KiB
7Elfogadva4/44ms4560 KiB
8Elfogadva5/594ms4840 KiB
9Időlimit túllépés0/21.062s13728 KiB
10Időlimit túllépés0/21.057s15216 KiB
11Elfogadva2/232ms8224 KiB
12Elfogadva2/2307ms8756 KiB
13Időlimit túllépés0/21.052s8232 KiB
14Időlimit túllépés0/21.057s8940 KiB
15Időlimit túllépés0/21.082s17208 KiB
16Időlimit túllépés0/21.067s18476 KiB
17Időlimit túllépés0/21.07s20888 KiB
18Időlimit túllépés0/21.047s20124 KiB
19Időlimit túllépés0/21.07s28468 KiB
20Időlimit túllépés0/31.05s25508 KiB