제출 #925273

#제출 시각아이디문제언어결과실행 시간메모리
925273TAhmed33도로 폐쇄 (APIO21_roads)C++17
컴파일 에러
0 ms0 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; const ll inf = 1e14; const int MAXN = 1e5 + 25; vector <pair <int, int>> adj[MAXN]; ll dp[MAXN][2], cur; int n; void dfs (int pos, int par) { ll sum = 0; for (auto j : adj[pos]) { if (j.first != par) { dfs(j.first, pos); sum += dp[j.first][0]; } } dp[pos][0] = dp[pos][1] = sum; vector <ll> k; for (auto j : adj[pos]) { if (j.first != par) { k.push_back(j.second + dp[j.first][1] - dp[j.first][0]); } } sort(k.begin(), k.end()); int z = (int)adj[pos].size() - (par != -1); ll mx1 = inf, mx2 = inf; sum = 0; k.insert(k.begin(), 0); int p1=max(0,z-cur-(par!=-1)); int p2=max(0,z-cur); for (int j = 0; j < (int)k.size(); j++) { sum += k[j]; if (j == p1) mx1 = min(mx1, sum); if (j == p2) mx2 = min(mx2, sum); } dp[pos][0] += mx1; dp[pos][1] += mx2; } vector <ll> minimum_closure_costs (int N, vector <int> u, vector <int> v, vector <int> w) { n = N; for (int i = 0; i + 1 < n; i++) { adj[u[i] + 1].push_back({v[i] + 1, w[i]}); adj[v[i] + 1].push_back({u[i] + 1, w[i]}); } vector <ll> ans = {}; for (int i = 0; i < n; i++) { cur = i; for (int j = 1; j <= n; j++) dp[j][0] = dp[j][1] = 0; dfs(1, -1); ans.push_back(dp[1][0]); } return ans; }

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

roads.cpp: In function 'void dfs(int, int)':
roads.cpp:28:31: error: no matching function for call to 'max(int, ll)'
   28 |   int p1=max(0,z-cur-(par!=-1));
      |                               ^
In file included from /usr/include/c++/10/bits/specfun.h:45,
                 from /usr/include/c++/10/cmath:1927,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:41,
                 from roads.cpp:1:
/usr/include/c++/10/bits/stl_algobase.h:254:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  254 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/10/bits/stl_algobase.h:254:5: note:   template argument deduction/substitution failed:
roads.cpp:28:31: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'll' {aka 'long long int'})
   28 |   int p1=max(0,z-cur-(par!=-1));
      |                               ^
In file included from /usr/include/c++/10/bits/specfun.h:45,
                 from /usr/include/c++/10/cmath:1927,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:41,
                 from roads.cpp:1:
/usr/include/c++/10/bits/stl_algobase.h:300:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  300 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/10/bits/stl_algobase.h:300:5: note:   template argument deduction/substitution failed:
roads.cpp:28:31: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'll' {aka 'long long int'})
   28 |   int p1=max(0,z-cur-(par!=-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:1:
/usr/include/c++/10/bits/stl_algo.h:3480:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(std::initializer_list<_Tp>)'
 3480 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/10/bits/stl_algo.h:3480:5: note:   template argument deduction/substitution failed:
roads.cpp:28:31: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   28 |   int p1=max(0,z-cur-(par!=-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:1:
/usr/include/c++/10/bits/stl_algo.h:3486:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(std::initializer_list<_Tp>, _Compare)'
 3486 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/10/bits/stl_algo.h:3486:5: note:   template argument deduction/substitution failed:
roads.cpp:28:31: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   28 |   int p1=max(0,z-cur-(par!=-1));
      |                               ^
roads.cpp:29:21: error: no matching function for call to 'max(int, ll)'
   29 |   int p2=max(0,z-cur);
      |                     ^
In file included from /usr/include/c++/10/bits/specfun.h:45,
                 from /usr/include/c++/10/cmath:1927,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:41,
                 from roads.cpp:1:
/usr/include/c++/10/bits/stl_algobase.h:254:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  254 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/10/bits/stl_algobase.h:254:5: note:   template argument deduction/substitution failed:
roads.cpp:29:21: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'll' {aka 'long long int'})
   29 |   int p2=max(0,z-cur);
      |                     ^
In file included from /usr/include/c++/10/bits/specfun.h:45,
                 from /usr/include/c++/10/cmath:1927,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:41,
                 from roads.cpp:1:
/usr/include/c++/10/bits/stl_algobase.h:300:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  300 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/10/bits/stl_algobase.h:300:5: note:   template argument deduction/substitution failed:
roads.cpp:29:21: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'll' {aka 'long long int'})
   29 |   int p2=max(0,z-cur);
      |                     ^
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:1:
/usr/include/c++/10/bits/stl_algo.h:3480:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(std::initializer_list<_Tp>)'
 3480 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/10/bits/stl_algo.h:3480:5: note:   template argument deduction/substitution failed:
roads.cpp:29:21: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   29 |   int p2=max(0,z-cur);
      |                     ^
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:1:
/usr/include/c++/10/bits/stl_algo.h:3486:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(std::initializer_list<_Tp>, _Compare)'
 3486 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/10/bits/stl_algo.h:3486:5: note:   template argument deduction/substitution failed:
roads.cpp:29:21: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   29 |   int p2=max(0,z-cur);
      |                     ^