66752023-12-15 22:21:27anonVillanyautócpp17Time limit exceeded 34/601.1s4984 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 k, ll Q, ll C, vector<vector<array<ll, 2>>> &G, unordered_set<ll> &vis, vector<array<ll, 2>> &states) {
    ll i;
    vis.insert(node);
    if(vis.size() == N)
        return true;
    if(states[node][0] != -1 && (states[node][0] > k || (states[node][0] == k && states[node][1] >= Q)))
        return false;
    states[node][0] = k;
    states[node][1] = Q;
    for(const auto [nn, weight] : G[node]) {
        if(weight <= Q)
            walk(nn, k, Q - weight, C, G, vis, states);
        else if(weight <= C && k > 0)
            walk(nn, k - 1, C - weight, C, G, vis, states);
    }
    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;
        bsmax = max(C, bsmax);
    }
    while(bsmin != bsmax - 1) {
        C = bsmin + (bsmax - bsmin) / 2;
        for(i = 1; i <= N; i++) {
            unordered_set<ll> vis(N);
            vector<array<ll, 2>> states(N + 1, { -1, -1 });
            if(!walk(i, K, 0, C, G, vis, states)) {
                bsmin = C;
                goto next;
            }
        }
        bsmax = C;
        next:;
    }
    cout << bsmax << '\n';
    return 0;
}

SubtaskSumTestVerdictTimeMemory
base34/60
1Accepted0/03ms1832 KiB
2Time limit exceeded0/01.1s1400 KiB
3Wrong answer0/13ms2316 KiB
4Accepted1/117ms2636 KiB
5Accepted1/123ms2824 KiB
6Wrong answer0/23ms2744 KiB
7Accepted2/290ms3028 KiB
8Accepted2/2137ms3292 KiB
9Time limit exceeded0/11.039s2952 KiB
10Time limit exceeded0/11.046s3304 KiB
11Time limit exceeded0/11.07s2596 KiB
12Time limit exceeded0/21.062s3464 KiB
13Time limit exceeded0/21.062s2632 KiB
14Time limit exceeded0/21.057s2944 KiB
15Time limit exceeded0/31.06s3756 KiB
16Time limit exceeded0/31.072s4172 KiB
17Wrong answer0/23ms4356 KiB
18Accepted2/219ms4408 KiB
19Accepted2/219ms4288 KiB
20Accepted2/221ms4480 KiB
21Accepted2/2488ms4368 KiB
22Accepted2/212ms4304 KiB
23Wrong answer0/34ms4304 KiB
24Accepted3/3112ms4632 KiB
25Accepted3/3286ms4860 KiB
26Accepted3/3173ms4984 KiB
27Time limit exceeded0/31.067s4092 KiB
28Accepted3/375ms4948 KiB
29Accepted3/371ms4760 KiB
30Accepted3/3375ms4856 KiB