66782023-12-15 22:43:16anonVillanyautócpp17Elfogadva 60/60731ms4272 KiB
#include <bits/stdc++.h>
#define FastIO ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define all(x) x.begin(), x.end()
typedef long long ll;
using namespace std;
const ll INF = ~(1LL << 63);
ll N, M, K;
bool walk(ll node, ll C, vector<vector<array<ll, 2>>> &G) {
    ll i;
    unordered_set<ll> vis(N);
    vector<array<ll, 2>> best(N + 1, { -1, -1 });
    queue<array<ll, 3>> q;
    q.push({ node, K, 0 });
    while(!q.empty()) {
        array<ll, 3> cs = q.front();
        q.pop();
        vis.insert(cs[0]);
        if(vis.size() == N)
            return true;
        if(best[cs[0]][0] != -1 && (best[cs[0]][0] > cs[1] || (best[cs[0]][0] == cs[1] && best[cs[0]][1] >= cs[2])))
            continue;
        best[cs[0]][0] = cs[1];
        best[cs[0]][1] = cs[2];
        for(const auto &x : G[cs[0]]) {
            if(x[1] <= cs[2])
                q.push({ x[0], cs[1], cs[2] - x[1] });
            else if(x[1] <= C && cs[1] > 0)
                q.push({ x[0], cs[1] - 1, C - x[1] });
        }
    }
    return vis.size() == N;
}
int main() {
    FastIO;
    ll i, n1, n2, C, bsmin, bsmax;
    cin >> N >> M >> K;
    vector<vector<array<ll, 2>>> G(N + 1);
    bsmin = INF;
    bsmax = 0;
    for(i = 0; i < M; i++) {
        cin >> n1 >> n2 >> C;
        G[n1].push_back({ n2, C });
        G[n2].push_back({ n1, C });
        bsmin = min(C, bsmin);
        bsmax += C;
    }
    while(bsmin != bsmax - 1) {
        C = bsmin + (bsmax - bsmin) / 2;
        for(i = 1; i <= N; i++) {
            if(!walk(i, C, G)) {
                bsmin = C;
                goto next;
            }
        }
        bsmax = C;
        next:;
    }
    cout << bsmax << '\n';
    return 0;
}

RészfeladatÖsszpontTesztVerdiktIdőMemória
base60/60
1Elfogadva0/03ms1832 KiB
2Elfogadva0/0731ms2540 KiB
3Elfogadva1/127ms2400 KiB
4Elfogadva1/132ms2708 KiB
5Elfogadva1/135ms3116 KiB
6Elfogadva2/2128ms2808 KiB
7Elfogadva2/2167ms3320 KiB
8Elfogadva2/2263ms3676 KiB
9Elfogadva1/16ms3032 KiB
10Elfogadva1/14ms3108 KiB
11Elfogadva1/14ms3184 KiB
12Elfogadva2/220ms3204 KiB
13Elfogadva2/212ms3344 KiB
14Elfogadva2/28ms3192 KiB
15Elfogadva3/312ms3412 KiB
16Elfogadva3/382ms3796 KiB
17Elfogadva2/214ms3432 KiB
18Elfogadva2/232ms3672 KiB
19Elfogadva2/235ms3688 KiB
20Elfogadva2/241ms3852 KiB
21Elfogadva2/297ms3580 KiB
22Elfogadva2/210ms3504 KiB
23Elfogadva3/364ms3508 KiB
24Elfogadva3/3160ms3836 KiB
25Elfogadva3/3167ms3992 KiB
26Elfogadva3/3254ms4272 KiB
27Elfogadva3/3558ms3824 KiB
28Elfogadva3/378ms3516 KiB
29Elfogadva3/364ms3792 KiB
30Elfogadva3/396ms3860 KiB