Submission #1162896

#TimeUsernameProblemLanguageResultExecution timeMemory
1162896tsengang경주 (Race) (IOI11_race)C++17
21 / 100
3096 ms28740 KiB
#include <bits/stdc++.h>
#include "race.h" 
using namespace std;
#define ll int
#define ff first
#define ss second
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define ertunt return
#define vodka void
vector<pair<int,int>>v[1000006];
ll ans;

vodka dfs(int i, int j, int cur, int d, int k){
    if(cur == k){
        ans = min(ans, d);
        ertunt;
    }
    if(cur > k) ertunt;
    for(auto [x,y]: v[i]){
        if(x != j){
            dfs(x, i, cur + y, d + 1, k);
        }
    }
}

int best_path(int n, int k, int h[][2], int l[]){
    for(ll i = 1; i <= n; i++) v[i].clear();
    for(ll i = 0; i < n-1; i++){
        v[h[i][0]].pb({h[i][1], l[i]});
        v[h[i][1]].pb({h[i][0], l[i]});
    }
    ans = 1e9;
    for(ll i = 1; i <= n; i++) dfs(i, -1, 0, 0, k);
    ertunt ans == 1e9 ? -1 : ans;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...