Submission #969850

# Submission time Handle Problem Language Result Execution time Memory
969850 2024-04-25T16:55:43 Z europium Road Closures (APIO21_roads) C++17
Compilation error
0 ms 0 KB
#include "roads.h"

#include <vector>
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

void dfs(int node, int parent, int k, vector<vector<pair<int, int>>>& graph, vector<vector<ll>>& dp) {
    dp[node][0] = 0;
    dp[node][1] = 0;
    for (auto& edge : graph[node]) {
        int child = edge.first;
        int cost = edge.second;
        if (child == parent) {
            continue;
        }
        dfs(child, node, k, graph, dp);
        for (int i = k; i >= 0; --i) {
            dp[node][i] += min(dp[child][min(i, k)] , dp[child][0]);
        }
    }
}

vector<ll> minimum_closure_costs(int N, vector<int>& U, vector<int>& V, vector<int>& W) {
    vector<vector<pair<int, int>>> graph(N);
    for (int i = 0; i < N - 1; ++i) {
        graph[U[i]].push_back({V[i], W[i]});
        graph[V[i]].push_back({U[i], W[i]});
    }

    vector<vector<ll>> dp(N, vector<ll>(N + 1, numeric_limits<ll>::max()));

    vector<ll> result;
    for (int k = 0; k < N; ++k) {
        dfs(0, -1, k, graph, dp);
        result.push_back(dp[0][k]);
    }

    return result;
}

Compilation message

roads.cpp: In function 'void dfs(int, int, int, std::vector<std::vector<std::pair<int, int> > >&, std::vector<std::vector<long long int> >&)':
roads.cpp:14:13: warning: unused variable 'cost' [-Wunused-variable]
   14 |         int cost = edge.second;
      |             ^~~~
/usr/bin/ld: /tmp/ccG4nEs8.o: in function `main':
grader.cpp:(.text.startup+0x277): undefined reference to `minimum_closure_costs(int, std::vector<int, std::allocator<int> >, std::vector<int, std::allocator<int> >, std::vector<int, std::allocator<int> >)'
collect2: error: ld returned 1 exit status