제출 #1199761

#제출 시각아이디문제언어결과실행 시간메모리
1199761edga1경주 (Race) (IOI11_race)C++20
31 / 100
195 ms114396 KiB
#include <bits/stdc++.h>
using namespace std;

int dp[200005][105];
vector<pair<int,int>> a[200005];
int rez=1e9,k;

void dfs(int u, int p){
    for(int i=0; i<=k; i++) dp[u][i]=1e9;
    dp[u][0]=0;
    for(int i=0; i<a[u].size(); i++){
        int v=a[u][i].first, w=a[u][i].second;
        if(v!=p){
            dfs(v,u);
            for(int j=0; j<=k-w; j++){
                rez=min(rez,dp[v][j]+1+dp[u][k-w-j]);
            }
            for(int j=w; j<=k; j++){
                dp[u][j]=min(dp[u][j],1+dp[v][j-w]);
            }
        }
    }
}

int best_path(int n, int K, int h[][2], int l[]){
    k=K;
    for(int i=0; i<n-1; i++){
        a[h[i][0]].push_back({h[i][1],l[i]});
        a[h[i][1]].push_back({h[i][0],l[i]});
    }
    dfs(0,0);
    if(rez==1e9) return -1;
    return rez;
}
/*
int main(){
    int n,k;
    cin>>n>>k;
    int h[n-1][2], l[n-1];
    for(int i=0; i<n-1; i++){
        cin>>h[i][0]>>h[i][1]>>l[i];
    }
    cout<<best_path(n,k,h,l);
}
*/
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...