Submission #980674

#TimeUsernameProblemLanguageResultExecution timeMemory
980674vjudge1Road Closures (APIO21_roads)C++17
Compilation error
0 ms0 KiB
#include "roads.h" #include <bits/stdc++.h> using namespace std; #define ll long long #define all(a) a.begin(), a.end() vector<vector<vector<ll>>> dp; vector<vector<array<ll, 2>>> graph; vector<bool> used; void dfs(int n, int p, int dist, int k){ vector<array<ll, 2>> d; for(auto x : graph[n]){ if(x[0] != p){ dfs(x[0], n, x[1], k); d.push_back({dp[x[0]][k][1] - dp[x[0]][k][0], x[0]}); } } sort(all(d)); ll s1 = 0; for (int i = 0; i != (int)d.size() and (i < (int)graph[n].size() - k or d[i][0] < 0); i++) s1 += dp[d[i][1]][k][1], used[d[i][1]] = 1; for (auto x : graph[n]) if (x[0] != p and !used[x[0]]) s1 += dp[x[0]][k][0]; dp[n][k][0] = s1; for (int i = 0; i != (int)d.size() and (i < (int)graph[n].size() - k or d[i][0] < 0); i++) used[d[i][1]] = 0; if(n != 0){ s1 = 0; for(int i = 0; i != (int)d.size() and (i < (int)graph[n].size() - k - 1 or d[i][0] < 0); i ++) s1 += dp[d[i][1]][k][1], used[d[i][1]] = 1; s1 += dist; for(auto x : graph[n]) if(x[0] != p and !used[x[0]]) s1 += dp[x[0]][k][0]; dp[n][k][1] = s1; for (int i = 0; i != (int)d.size() and (i < (int)graph[n].size() - k - 1 or d[i][0] < 0); i++) used[d[i][1]] = 0; } } vector<ll> minimum_closure_costs(int n, vector<int> u, vector<int> v, vector<int> w) { if(count(all(u)) == n - 1){ vector<ll> ans(n); for(auto x : w) ans[0] += x; sort(all(w)); for(int i = n - 1; i >= 0; i --) ans[n - i] = ans[n - i - 1] - w[i]; return ans; } graph.resize(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]}); used.resize(n); dp.resize(n, vector<vector<ll>>(n, vector<ll>(2, 0))); for(int i = 1; i < n; i ++) dfs(0, -1, 0, i); vector<ll> ans(n); for(auto x : w) ans[0] += x; for(int i = 1; i < n; i ++) ans[i] = dp[0][i][0]; return ans; }

Compilation message (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:45:18: error: no matching function for call to 'count(std::vector<int>::iterator, std::vector<int>::iterator)'
   45 |   if(count(all(u)) == n - 1){
      |                  ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from roads.cpp:2:
/usr/include/c++/10/bits/stl_algo.h:4077:5: note: candidate: 'template<class _IIter, class _Tp> typename std::iterator_traits< <template-parameter-1-1> >::difference_type std::count(_IIter, _IIter, const _Tp&)'
 4077 |     count(_InputIterator __first, _InputIterator __last, const _Tp& __value)
      |     ^~~~~
/usr/include/c++/10/bits/stl_algo.h:4077:5: note:   template argument deduction/substitution failed:
roads.cpp:45:18: note:   candidate expects 3 arguments, 2 provided
   45 |   if(count(all(u)) == n - 1){
      |                  ^
In file included from /usr/include/c++/10/algorithm:74,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from roads.cpp:2:
/usr/include/c++/10/pstl/glue_algorithm_defs.h:101:1: note: candidate: 'template<class _ExecutionPolicy, class _ForwardIterator, class _Tp> __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, typename std::iterator_traits<_II>::difference_type> std::count(_ExecutionPolicy&&, _ForwardIterator, _ForwardIterator, const _Tp&)'
  101 | count(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last, const _Tp& __value);
      | ^~~~~
/usr/include/c++/10/pstl/glue_algorithm_defs.h:101:1: note:   template argument deduction/substitution failed:
roads.cpp:45:18: note:   candidate expects 4 arguments, 2 provided
   45 |   if(count(all(u)) == n - 1){
      |                  ^