제출 #1264313

#제출 시각아이디문제언어결과실행 시간메모리
1264313BlockOG경주 (Race) (IOI11_race)C++20
21 / 100
3091 ms9972 KiB
#include <bits/stdc++.h>

// mrrrow meeow :3
// go play vivid/stasis now! it's free on steam

#define fo(i, a, b) for (auto i = (a); i < (b); i++)
#define of(i, a, b) for (auto i = (b); i-- > (a);)
#define f first
#define s second
#define pb push_back
#define pob pop_back
#define lb lower_bound
#define ub upper_bound
#define be(a) a.begin(), a.end()
using namespace std;

int ____init = [] {
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    return 0;
}();

vector<pair<int, int>> adj[200000];

int dfs(int i, int d, int p = -1) {
    if (d == 0) return 0;
    if (d < 0) return 1000000;

    int md = 1000000;
    for (auto [j, l] : adj[i]) {
        if (j == p) continue;
        md = min(md, dfs(j, d - l, i));
    }

    return md + 1;
}

int best_path(int n, int k, int h[][2], int l[]) {
    fo(i, 0, n - 1) {
        adj[h[i][0]].pb({h[i][1], l[i]});
        adj[h[i][1]].pb({h[i][0], l[i]});
    }

    int res = 1000000;
    fo(i, 0, n) {
        res = min(res, dfs(i, k));
    }

    return res == 1000000 ? -1 : res;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...