231282026-01-16 12:54:41MagyarKendeSZLGVillanyautócpp17Wrong answer 8/60289ms756 KiB
#include <bits/stdc++.h>
using namespace std;
#define int int64_t

const int INF = 1e18;

int32_t main() {
    cin.tie(0), ios::sync_with_stdio(0);
    int n, m, k;
    cin >> n >> m >> 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 = 1e12;
    while (r - l > 1) {
        int mid = (l + r) / 2;
        if (f(mid)) {
            r = mid;
        } else {
            l = mid;
        }
    }
    cout << r << "\n";
}
SubtaskSumTestVerdictTimeMemory
base8/60
1Accepted0/01ms508 KiB
2Accepted0/097ms316 KiB
3Wrong answer0/120ms500 KiB
4Wrong answer0/143ms316 KiB
5Wrong answer0/156ms524 KiB
6Wrong answer0/279ms428 KiB
7Wrong answer0/2165ms392 KiB
8Wrong answer0/2289ms756 KiB
9Wrong answer0/117ms316 KiB
10Wrong answer0/18ms316 KiB
11Wrong answer0/16ms316 KiB
12Wrong answer0/268ms316 KiB
13Wrong answer0/243ms316 KiB
14Wrong answer0/219ms316 KiB
15Wrong answer0/350ms316 KiB
16Wrong answer0/3107ms504 KiB
17Wrong answer0/29ms316 KiB
18Wrong answer0/241ms316 KiB
19Wrong answer0/243ms316 KiB
20Wrong answer0/250ms684 KiB
21Accepted2/217ms316 KiB
22Wrong answer0/28ms316 KiB
23Wrong answer0/339ms316 KiB
24Wrong answer0/3159ms316 KiB
25Wrong answer0/3150ms540 KiB
26Wrong answer0/3234ms624 KiB
27Accepted3/394ms316 KiB
28Wrong answer0/346ms316 KiB
29Wrong answer0/339ms436 KiB
30Accepted3/348ms316 KiB