Submission #969849

#TimeUsernameProblemLanguageResultExecution timeMemory
969849europiumRoad Closures (APIO21_roads)C++17
Compilation error
0 ms0 KiB
#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<int>>& 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 (stderr)

roads.cpp: In function 'void dfs(int, int, int, std::vector<std::vector<std::pair<int, int> > >&, std::vector<std::vector<int> >&)':
roads.cpp:14:13: warning: unused variable 'cost' [-Wunused-variable]
   14 |         int cost = edge.second;
      |             ^~~~
roads.cpp: In function 'std::vector<long long int> minimum_closure_costs(int, std::vector<int>&, std::vector<int>&, std::vector<int>&)':
roads.cpp:36:30: error: invalid initialization of reference of type 'std::vector<std::vector<int> >&' from expression of type 'std::vector<std::vector<long long int> >'
   36 |         dfs(0, -1, k, graph, dp);
      |                              ^~
roads.cpp:9:99: note: in passing argument 5 of 'void dfs(int, int, int, std::vector<std::vector<std::pair<int, int> > >&, std::vector<std::vector<int> >&)'
    9 | void dfs(int node, int parent, int k, vector<vector<pair<int, int>>>& graph, vector<vector<int>>& dp) {
      |                                                                              ~~~~~~~~~~~~~~~~~~~~~^~