제출 #969849

#제출 시각아이디문제언어결과실행 시간메모리
969849europium도로 폐쇄 (APIO21_roads)C++17
컴파일 에러
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; }

컴파일 시 표준 에러 (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) {
      |                                                                              ~~~~~~~~~~~~~~~~~~~~~^~