제출 #554558

#제출 시각아이디문제언어결과실행 시간메모리
554558Zhora_004도로 폐쇄 (APIO21_roads)C++17
컴파일 에러
0 ms0 KiB
#include "roads.h" #include <iostream> #include <cmath> #include <algorithm> #include <vector> #include <set> #include <unordered_set> #include <queue> #include <deque> #include <string> #include <sstream> #include <iomanip> #include <map> #include <unordered_map> #include <stack> #include <cstdio> #include <climits> #include <tuple> #include <ctime> #include <cstring> #include <numeric> #include <functional> #include <chrono> #include <cassert> #include <bitset> #include <fstream> #define sz(a) ((int)((a).size())) using ll = long long; using namespace std; const int inf = 1e9; int n, k; vector<int> a, b, c; vector<vector<pair<int, int>>> tree; vector<vector<ll>> dp; void dfs(int u, int p, int w) { for (pair<int, int>& edge : tree[u]) if (edge.first != p) dfs(edge.first, u, edge.second); int can = k; dp[u][0] = 0; if (p != -1) can--; int cnt = sz(tree[u]); if (p != -1) cnt--; vector<vector<ll>> d(cnt + 1, vector<ll>(can + 1, 1ll * inf * inf)); d[0][0] = 0; int cur = 1; for (int i = 0; i < sz(tree[u]); i++) { int v = tree[u][i].first; if (v == p) continue; for (int j = 0; j <= min(cur, can); j++) { if (cur - 1 >= j) d[cur][j] = d[cur - 1][j] + dp[v][1]; if (j) d[cur][j] = min(d[cur][j], d[cur - 1][j - 1] + dp[v][0]); } cur++; } dp[u][0] = 1ll * inf * inf; for (int j = 0; j <= can; j++) dp[u][0] = min(dp[u][0], d[cnt][j]); if (p != -1) { can = k; d = vector<vector<ll>>(cnt + 1, vector<ll>(can + 1, 1ll * inf * inf)); d[0][0] = 0; cur = 1; for (int i = 0; i < sz(tree[u]); i++) { int v = tree[u][i].first; if (v == p) continue; for (int j = 0; j <= min(cur, can); j++) { if (cur - 1 >= j) d[cur][j] = d[cur - 1][j] + dp[v][1]; if (j) d[cur][j] = min(d[cur][j], d[cur - 1][j - 1] + dp[v][0]); } cur++; } dp[u][1] = 1ll * inf * inf; for (int j = 0; j <= can; j++) dp[u][1] = min(dp[u][1], d[cnt][j]); dp[u][1] += w; } } std::vector<long long> minimum_closure_costs(int N, std::vector<int> U, std::vector<int> V, std::vector<int> W) { n = N; a = U; b = V; c = W; ll tmp = 0; tree = vector<pair<int, int>>(n); for (int i = 0; i < n - 1; i++) { int u, v, w; u = a[i], v = b[i], w = c[i]; tree[u].push_back({ v, w }); tree[v].push_back({ u, w }); tmp += w; } vector<ll> res; res.push_back(tmp); for (k = 1; k < n; k++) { dp = vector<vector<ll>>(n, vector<ll>(2)); dfs(0, -1, -1); res.push_back(dp[0][0]); } return res; }

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

roads.cpp: In function 'std::vector<long long int> minimum_closure_costs(int, std::vector<int>, std::vector<int>, std::vector<int>)':
roads.cpp:90:33: error: no match for 'operator=' (operand types are 'std::vector<std::vector<std::pair<int, int> > >' and 'std::vector<std::pair<int, int> >')
   90 |  tree = vector<pair<int, int>>(n);
      |                                 ^
In file included from /usr/include/c++/10/vector:72,
                 from roads.h:1,
                 from roads.cpp:1:
/usr/include/c++/10/bits/vector.tcc:198:5: note: candidate: 'std::vector<_Tp, _Alloc>& std::vector<_Tp, _Alloc>::operator=(const std::vector<_Tp, _Alloc>&) [with _Tp = std::vector<std::pair<int, int> >; _Alloc = std::allocator<std::vector<std::pair<int, int> > >]'
  198 |     vector<_Tp, _Alloc>::
      |     ^~~~~~~~~~~~~~~~~~~
/usr/include/c++/10/bits/vector.tcc:199:42: note:   no known conversion for argument 1 from 'std::vector<std::pair<int, int> >' to 'const std::vector<std::vector<std::pair<int, int> > >&'
  199 |     operator=(const vector<_Tp, _Alloc>& __x)
      |               ~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~
In file included from /usr/include/c++/10/vector:67,
                 from roads.h:1,
                 from roads.cpp:1:
/usr/include/c++/10/bits/stl_vector.h:709:7: note: candidate: 'std::vector<_Tp, _Alloc>& std::vector<_Tp, _Alloc>::operator=(std::vector<_Tp, _Alloc>&&) [with _Tp = std::vector<std::pair<int, int> >; _Alloc = std::allocator<std::vector<std::pair<int, int> > >]'
  709 |       operator=(vector&& __x) noexcept(_Alloc_traits::_S_nothrow_move())
      |       ^~~~~~~~
/usr/include/c++/10/bits/stl_vector.h:709:26: note:   no known conversion for argument 1 from 'std::vector<std::pair<int, int> >' to 'std::vector<std::vector<std::pair<int, int> > >&&'
  709 |       operator=(vector&& __x) noexcept(_Alloc_traits::_S_nothrow_move())
      |                 ~~~~~~~~~^~~
/usr/include/c++/10/bits/stl_vector.h:730:7: note: candidate: 'std::vector<_Tp, _Alloc>& std::vector<_Tp, _Alloc>::operator=(std::initializer_list<_Tp>) [with _Tp = std::vector<std::pair<int, int> >; _Alloc = std::allocator<std::vector<std::pair<int, int> > >]'
  730 |       operator=(initializer_list<value_type> __l)
      |       ^~~~~~~~
/usr/include/c++/10/bits/stl_vector.h:730:46: note:   no known conversion for argument 1 from 'std::vector<std::pair<int, int> >' to 'std::initializer_list<std::vector<std::pair<int, int> > >'
  730 |       operator=(initializer_list<value_type> __l)
      |                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~