답안 #1005240

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1005240 2024-06-22T09:15:19 Z cpdreamer 경주 (Race) (IOI11_race) C++17
컴파일 오류
0 ms 0 KB
#include "race.h"
#include<bits/stdc++.h>
using namespace std;
#define P pair
#define V vector
#define F first
#define S second
#define pb push_back
typedef long long ll;
ll dp[(ll)300000][110];
void dfs(ll n,ll p,V<P<ll,ll>>tree[],ll k){
    dp[n][0]=0;
    for(auto u:tree[n]){
        if(u.F==p)continue;
        dfs(u.F,n,tree,k);
        for(ll i=u.S;i<=k;i++){
            if(dp[u.F][i-u.S]!=-1){
                if(dp[n][i]!=-1)
                    dp[n][i]=min(dp[n][i],dp[u.F][i-u.S]+1);
                else
                    dp[n][i]=dp[u.F][i-u.S]+1;
            }
        }
    }
}
ll best_path(ll N, ll K, ll H[][2], ll L[])
{
    memset(dp,-1,sizeof(dp));
    V<P<ll,ll>>tree[N];
    for(ll i=0;i<N-1;i++){
        tree[H[i][0]].pb({H[i][1],L[i]});
        tree[H[i][1]].pb({H[i][0],L[i]});
    }
    dfs(0,-1,tree,K);
    ll ans=-1;
    for(ll i=0;i<N;i++){
        if(dp[i][K]!=-1) {
            if(ans!=-1)
                ans = min(dp[i][K], ans);
            else
                ans=dp[i][K];
        }
    }
    return ans;
}

Compilation message

/usr/bin/ld: /tmp/ccxyJC0P.o: in function `main':
grader.cpp:(.text.startup+0x28): undefined reference to `best_path(int, int, int (*) [2], int*)'
collect2: error: ld returned 1 exit status