제출 #1223386

#제출 시각아이디문제언어결과실행 시간메모리
1223386SpyrosAliv도로 폐쇄 (APIO21_roads)C++20
컴파일 에러
0 ms0 KiB
#include "roads.h"
using namespace std;
#define ll long long

vector<vector<pair<int, ll>>> tree;
vector<vector<ll>> dp;
int n;

void dfs(int node, int par = 0) {
    for (auto [next, w]: tree[node]) {
        if (next == par) continue;
        dfs(next, node);
    }
    for (int k = 0; k <= n; k++) {
        ll ans = 0;
        if (k == 0) {
            for (auto [next, w]: tree[node]) {
                if (next == par) continue;
                ans += w;
            }
            dp[i][k] = ans;
            continue;
        }   
        vector<ll> ops;
        for (auto [next, w]: tree[node]) {
            if (next == par) continue;
            ops.push_back(dp[next][k] - (dp[next][k-1] + w));
            ans += dp[next][k-1] + w;
        }
        sort(ops.begin(), ops.end());
        if (ops.size() < k) {
            dp[node][k] = INF;
            continue;
        }
        for (int j = 0; j < k; j++) {
            ans += ops[j];
        }
        dp[node][k] = ans;
    }
}

vector<ll> minimum_closure_costs(int N, vector<int> U, vector<int> V, vector<int> W) {
    n = N;
    tree.resize(n+1);
    for (int i = 0; i < n; i++) {
        U[i]++;
        V[i]++;
        tree[U[i]].push_back({V[i], W[i]});
        tree[V[i]].push_back({U[i], W[i]});
    }
    dp.assign(n+1, 0);
    dfs(1);
    vector<ll> ans;
    for (int k = 1; k <= n; k++) dp[1][k] = min(dp[1][k], dp[1][k-1]);
    for (int k = 0; k <= n; k++) ans.push_back(dp[1][i]);
    return ans;
}

컴파일 시 표준 에러 (stderr) 메시지

roads.cpp: In function 'void dfs(int, int)':
roads.cpp:21:16: error: 'i' was not declared in this scope
   21 |             dp[i][k] = ans;
      |                ^
roads.cpp:32:27: error: 'INF' was not declared in this scope
   32 |             dp[node][k] = INF;
      |                           ^~~
roads.cpp: In function 'std::vector<long long int> minimum_closure_costs(int, std::vector<int>, std::vector<int>, std::vector<int>)':
roads.cpp:51:14: error: no matching function for call to 'std::vector<std::vector<long long int> >::assign(int, int)'
   51 |     dp.assign(n+1, 0);
      |     ~~~~~~~~~^~~~~~~~
In file included from /usr/include/c++/11/vector:67,
                 from roads.h:1,
                 from roads.cpp:1:
/usr/include/c++/11/bits/stl_vector.h:768:9: note: candidate: 'template<class _InputIterator, class> void std::vector<_Tp, _Alloc>::assign(_InputIterator, _InputIterator) [with _InputIterator = _InputIterator; <template-parameter-2-2> = <template-parameter-1-2>; _Tp = std::vector<long long int>; _Alloc = std::allocator<std::vector<long long int> >]'
  768 |         assign(_InputIterator __first, _InputIterator __last)
      |         ^~~~~~
/usr/include/c++/11/bits/stl_vector.h:768:9: note:   template argument deduction/substitution failed:
In file included from /usr/include/c++/11/bits/stl_algobase.h:65,
                 from /usr/include/c++/11/vector:60,
                 from roads.h:1,
                 from roads.cpp:1:
/usr/include/c++/11/bits/stl_iterator_base_types.h: In substitution of 'template<class _InIter> using _RequireInputIter = std::__enable_if_t<std::is_convertible<typename std::iterator_traits< <template-parameter-1-1> >::iterator_category, std::input_iterator_tag>::value> [with _InIter = int]':
/usr/include/c++/11/bits/stl_vector.h:766:9:   required from here
/usr/include/c++/11/bits/stl_iterator_base_types.h:249:11: error: no type named 'iterator_category' in 'struct std::iterator_traits<int>'
  249 |     using _RequireInputIter =
      |           ^~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/11/vector:67,
                 from roads.h:1,
                 from roads.cpp:1:
/usr/include/c++/11/bits/stl_vector.h:749:7: note: candidate: 'void std::vector<_Tp, _Alloc>::assign(std::vector<_Tp, _Alloc>::size_type, const value_type&) [with _Tp = std::vector<long long int>; _Alloc = std::allocator<std::vector<long long int> >; std::vector<_Tp, _Alloc>::size_type = long unsigned int; std::vector<_Tp, _Alloc>::value_type = std::vector<long long int>]'
  749 |       assign(size_type __n, const value_type& __val)
      |       ^~~~~~
/usr/include/c++/11/bits/stl_vector.h:749:47: note:   no known conversion for argument 2 from 'int' to 'const value_type&' {aka 'const std::vector<long long int>&'}
  749 |       assign(size_type __n, const value_type& __val)
      |                             ~~~~~~~~~~~~~~~~~~^~~~~
/usr/include/c++/11/bits/stl_vector.h:794:7: note: candidate: 'void std::vector<_Tp, _Alloc>::assign(std::initializer_list<_Tp>) [with _Tp = std::vector<long long int>; _Alloc = std::allocator<std::vector<long long int> >]'
  794 |       assign(initializer_list<value_type> __l)
      |       ^~~~~~
/usr/include/c++/11/bits/stl_vector.h:794:7: note:   candidate expects 1 argument, 2 provided
roads.cpp:55:54: error: 'i' was not declared in this scope
   55 |     for (int k = 0; k <= n; k++) ans.push_back(dp[1][i]);
      |                                                      ^