66742023-12-15 22:16:26anonVillanyautócpp17Időlimit túllépés 57/601.1s5024 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;
    }
    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;
}

RészfeladatÖsszpontTesztVerdiktIdőMemória
base57/60
1Elfogadva0/03ms1824 KiB
2Időlimit túllépés0/01.1s1392 KiB
3Elfogadva1/150ms2348 KiB
4Elfogadva1/134ms2740 KiB
5Elfogadva1/143ms2868 KiB
6Elfogadva2/2199ms3036 KiB
7Elfogadva2/2197ms3200 KiB
8Elfogadva2/2296ms3536 KiB
9Elfogadva1/18ms3068 KiB
10Elfogadva1/14ms3196 KiB
11Elfogadva1/14ms3300 KiB
12Elfogadva2/292ms3556 KiB
13Elfogadva2/219ms3624 KiB
14Elfogadva2/28ms3848 KiB
15Elfogadva3/316ms3700 KiB
16Elfogadva3/3950ms3776 KiB
17Elfogadva2/219ms3992 KiB
18Elfogadva2/234ms4144 KiB
19Elfogadva2/237ms4476 KiB
20Elfogadva2/241ms4480 KiB
21Elfogadva2/2901ms4492 KiB
22Elfogadva2/29ms4468 KiB
23Elfogadva3/3127ms4604 KiB
24Elfogadva3/3178ms4888 KiB
25Elfogadva3/3375ms4652 KiB
26Elfogadva3/3330ms4816 KiB
27Időlimit túllépés0/31.042s4832 KiB
28Elfogadva3/3108ms4884 KiB
29Elfogadva3/3116ms5024 KiB
30Elfogadva3/3588ms4956 KiB