231362026-01-16 13:08:12MagyarKendeSZLGVillanyautócpp17Accepted 60/60282ms580 KiB
#include <bits/stdc++.h>
using namespace std;
#define int int64_t

const int INF = 1e12;

int32_t main() {
    cin.tie(0), ios::sync_with_stdio(0);
    int n, m, k;
    cin >> n >> m >> k;
    k--;
    vector<vector<array<int, 2>>> g(n + 1);
    while (m--) {
        int u, v, w;
        cin >> u >> v >> w;
        g[u].push_back({v, w});
        g[v].push_back({u, w});
    }

    auto check = [&](int start, int cap) -> bool {
        auto calc = [&](int ch, int cp,
                        int w) -> array<int, 2> {
            if (w > cap) return {INF, INF};
            if (cp + w <= cap) return {ch, cp + w};
            return {ch + 1, w};
        };
        using state = array<int, 3>;
        priority_queue<state, vector<state>, greater<state>>
            pq;
        vector<array<int, 2>> dist(n + 1, {INF, INF});
        dist[start] = {0, 0};
        pq.push({0, 0, start});
        while (!pq.empty()) {
            auto [ch, cp, u] = pq.top();
            pq.pop();
            if (dist[u][0] != ch || dist[u][1] != cp) {
                continue;
            }
            for (auto [v, w] : g[u]) {
                auto nc = calc(ch, cp, w);
                if (nc < dist[v]) {
                    dist[v] = nc;
                    pq.push({nc[0], nc[1], v});
                }
            }
        }
        for (int i = 1; i <= n; i++) {
            if (dist[i][0] > k) return 0;
        }
        return 1;
    };
    auto f = [&](int cap) -> bool {
        for (int start = 1; start <= n; start++) {
            if (!check(start, cap)) return 0;
        }
        return 1;
    };

    int l = 0, r = INF;
    while (r - l > 1) {
        int mid = (l + r) / 2;
        if (f(mid)) {
            r = mid;
        } else {
            l = mid;
        }
    }
    cout << r << "\n";
}
SubtaskSumTestVerdictTimeMemory
base60/60
1Accepted0/01ms500 KiB
2Accepted0/098ms316 KiB
3Accepted1/117ms316 KiB
4Accepted1/141ms316 KiB
5Accepted1/150ms316 KiB
6Accepted2/289ms316 KiB
7Accepted2/2170ms316 KiB
8Accepted2/2282ms568 KiB
9Accepted1/117ms316 KiB
10Accepted1/18ms428 KiB
11Accepted1/16ms512 KiB
12Accepted2/267ms436 KiB
13Accepted2/246ms508 KiB
14Accepted2/219ms508 KiB
15Accepted3/350ms316 KiB
16Accepted3/3108ms504 KiB
17Accepted2/28ms316 KiB
18Accepted2/239ms316 KiB
19Accepted2/241ms316 KiB
20Accepted2/252ms316 KiB
21Accepted2/217ms316 KiB
22Accepted2/28ms316 KiB
23Accepted3/339ms428 KiB
24Accepted3/3150ms316 KiB
25Accepted3/3143ms512 KiB
26Accepted3/3243ms580 KiB
27Accepted3/396ms316 KiB
28Accepted3/354ms316 KiB
29Accepted3/337ms500 KiB
30Accepted3/350ms316 KiB