Submission #1000824

# Submission time Handle Problem Language Result Execution time Memory
1000824 2024-06-18T09:45:13 Z Tsog Race (IOI11_race) C++17
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair

using namespace std;


const int INF = INT_MAX;

void dfs(int v, int parent, vector<vector<int>>& dp, const vector<vector<pair<int,int>>>& adj) {
	for (auto i = 0u; i < adj[v].size(); ++i) {
        int u = adj[v][i].first;
        int cos = adj[v][i].second;
        
        if (u == parent) {
            continue;
        }
        
        for (int k = cos; k <= 100; ++k) { 
            if (dp[v][k - cos] != INF) {
                dp[u][k] = min(dp[u][k], dp[v][k - cos] + 1);
            }
        }
        
        dfs(u, v, dp, adj);
    }
}


int best_path(int N, int K, vector<vector<int>>& H, vector<int>& L) {
    vector<vector<pair<int,int>>> adj(N);
    for (int i = 0; i < N - 1; ++i) {
        int u = H[i][0], v = H[i][1];
        adj[u].push_back(mp(v,L[i]));
        adj[v].push_back(mp(u,L[i]));
    }
    
    vector<vector<int>> dp(N, vector<int>(200001, INF));
    for(int i = 0 ; i < N ; i ++){
    	dp[i][0] = 0;
    }
    
    dfs(0, -1, dp, adj);
    
    int result = INF;
    for (int v = 0; v < N; ++v) {
        result = min(result, dp[v][K]);
    }
    
    return (result == INF ? -1 : result);
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
    int N;
    int K;
    int a , b , l , i;
    vector<vector<int>> H;
    vector<int> L;
    cin >> N >> K;
    for(i = 1 ; i < N ; i++){
    	cin >> a >> b;
    	H.pb({a , b});
    }
    for(i = 1 ; i < N ; i++){
    	cin >> l;
    	L.pb(l);
    }
    
    int min_highways = best_path(N, K, H, L);
    
    cout << min_highways;
}

Compilation message

/usr/bin/ld: /tmp/ccqFmXJ9.o: in function `main':
race.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/ccr8vOT7.o:grader.cpp:(.text.startup+0x0): first defined here
/usr/bin/ld: /tmp/ccr8vOT7.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