231352026-01-16 13:06:10MagyarKendeSZLGVillanyautócpp17Wrong answer 22/60282ms572 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, 0};
        };
        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
base22/60
1Accepted0/01ms316 KiB
2Accepted0/097ms432 KiB
3Accepted1/118ms316 KiB
4Accepted1/141ms508 KiB
5Accepted1/152ms316 KiB
6Accepted2/289ms572 KiB
7Accepted2/2168ms544 KiB
8Accepted2/2282ms384 KiB
9Wrong answer0/117ms508 KiB
10Wrong answer0/19ms424 KiB
11Wrong answer0/17ms316 KiB
12Wrong answer0/268ms320 KiB
13Wrong answer0/243ms424 KiB
14Accepted2/219ms316 KiB
15Accepted3/350ms500 KiB
16Wrong answer0/3107ms500 KiB
17Wrong answer0/210ms316 KiB
18Wrong answer0/241ms316 KiB
19Wrong answer0/243ms316 KiB
20Wrong answer0/254ms316 KiB
21Accepted2/217ms316 KiB
22Wrong answer0/29ms512 KiB
23Wrong answer0/341ms316 KiB
24Wrong answer0/3145ms520 KiB
25Wrong answer0/3153ms316 KiB
26Wrong answer0/3228ms564 KiB
27Accepted3/396ms496 KiB
28Wrong answer0/350ms492 KiB
29Wrong answer0/339ms508 KiB
30Accepted3/350ms440 KiB