66572023-12-15 17:25:25anonVillanyautócpp17Wrong answer 2/60800ms5348 KiB
#include <bits/stdc++.h>

#define MAX_N 100

#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, G[MAX_N + 1][MAX_N + 1];
bool vis[MAX_N + 1];
unordered_map<ll,array<ll,2>> states;

void walk(ll node, ll k, ll cap, ll max_cap) {
    if(cap < 0)
        return;

    auto found = states.find(node);

    if(found != states.end() && ((found->second[0] > k && found->second[1] > cap) || (found->second[0] == k && found->second[1] > cap) || (found->second[0] > k && found->second[1] == cap)))
        return;

    if(found == states.end())
        states[node] = { k, cap };
    else {
        found->second[0] = max(k, found->second[0]);
        found->second[1] = max(cap, found->second[1]);
    }

    vis[node] = true;

    if(k > 0)
        walk(node, k - 1, max_cap, max_cap);

    for(ll i = 1; i <= MAX_N; i++) {
        if(G[node][i])
            walk(i, k, cap - G[node][i], max_cap);
    }
}

int main()
{
    FastIO;
    ll n1, n2, C;
    set<ll> caps;
    cin >> N >> M >> K;
    for(ll i = 0; i < M; i++) {
        cin >> n1 >> n2 >> C;
        G[n1][n2] = C;
        G[n2][n1] = C;
        caps.insert(C);
    }
    set<ll>::iterator it;
    for(it = caps.begin(); it != caps.end(); it++) {
        fill(vis + 1, vis + N + 1, false);
        states.clear();
        walk(1, K, 0, *it);
        if(all_of(vis + 1, vis + N + 1, [](auto &a) { return a; })) {
            cout << *it << '\n';
            break;
        }
    }
    return 0;
}

SubtaskSumTestVerdictTimeMemory
base2/60
1Accepted0/03ms1832 KiB
2Accepted0/0800ms2300 KiB
3Wrong answer0/14ms2440 KiB
4Wrong answer0/13ms2696 KiB
5Wrong answer0/13ms3096 KiB
6Wrong answer0/24ms3068 KiB
7Wrong answer0/24ms3400 KiB
8Wrong answer0/24ms3928 KiB
9Wrong answer0/13ms3760 KiB
10Wrong answer0/13ms3996 KiB
11Wrong answer0/13ms3956 KiB
12Wrong answer0/23ms4024 KiB
13Wrong answer0/23ms3964 KiB
14Wrong answer0/23ms4240 KiB
15Wrong answer0/33ms4208 KiB
16Wrong answer0/33ms4348 KiB
17Wrong answer0/23ms4424 KiB
18Wrong answer0/24ms4552 KiB
19Wrong answer0/23ms4580 KiB
20Wrong answer0/24ms4612 KiB
21Accepted2/286ms4460 KiB
22Wrong answer0/23ms4460 KiB
23Wrong answer0/34ms4512 KiB
24Wrong answer0/36ms4688 KiB
25Wrong answer0/36ms4992 KiB
26Wrong answer0/38ms5244 KiB
27Wrong answer0/3189ms5132 KiB
28Wrong answer0/34ms4984 KiB
29Wrong answer0/34ms5116 KiB
30Wrong answer0/314ms5348 KiB