Submission #518998

#TimeUsernameProblemLanguageResultExecution timeMemory
518998fabijan_cikacRace (IOI11_race)C++17
Compilation error
0 ms0 KiB
#include <bits/stdc++.h> using namespace std; typedef long long int ll; typedef pair<ll, ll> pp; const ll MAXN = 2 * 1e5 + 100; const ll INF = 1e9; struct mapa{ ll val = INF; }; int n; ll k; vector<pp> v[MAXN]; int p[MAXN] = { 0 }; ll vel[MAXN] = { 0 }; map<ll, mapa> m; vector<ll> s; ll sol = INF; ll cnt = 0; int dfs(int x, int depth, ll sum, int val, ll k){ p[x] = 1; if (val == 0) ++cnt; else if (val == 1 && sum <= k){ ll zb = depth + m[k - sum].val - 1; sol = min(sol, zb); } else if (val == 2 && sum <= k){ s.push_back(sum); m[sum].val = min(m[sum].val, depth); } for (int i = 0; i < v[x].size(); ++i){ int y = v[x][i].first; if (!p[y]){ ll rt = dfs(y, depth + 1, sum + v[x][i].second, val, k); if (val == 0) vel[x] += rt; } } if (val == 0) ++vel[x]; p[x] = 0; if (val == 0) return vel[x]; return 0; } int centr(int x){ pp maks = {-1, -1}; for (int i = 0; i < v[x].size(); ++i){ int y = v[x][i].first; if (!p[y] && vel[y] > maks.second) maks = {y, vel[y]}; } if (maks.second <= cnt / 2) return x; return maks.first; } void solve(int x, int K){ s.clear(); for (int i = 0; i < v[x].size(); ++i){ int y = v[x][i].first; if (!p[y]){ dfs(y, 2, v[x][i].second, 1, K); dfs(y, 2, v[x][i].second, 2, K); } } for (int i = 0; i < s.size(); ++i) m[s[i]].val = INF; s.clear(); return; } void decompose(int x, int K){ cnt = 0; dfs(x, 1, 0, 0, K); int root = centr(x); p[root] = 1; solve(root, K); for (int i = 0; i < v[root].size(); ++i){ int y = v[root][i].first; if (!p[y]) decompose(y, K); } } int best_path(int N, int K, int H[MAXN][2], int L[MAXN]){ ios_base::sync_with_stdio(false); cin.tie(NULL); for (int i = 0; i < N - 1; ++i){ v[H[i][0]].push_back({H[i][1], L[i]}); v[H[i][1]].push_back({H[i][0], L[i]}); } decompose(0, K); if (sol == INF) return -1; else return (sol - 1); return 0; }

Compilation message (stderr)

race.cpp: In function 'int dfs(int, int, ll, int, ll)':
race.cpp:34:43: error: no matching function for call to 'min(ll&, int&)'
   34 |         m[sum].val = min(m[sum].val, depth);
      |                                           ^
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 race.cpp:1:
/usr/include/c++/10/bits/stl_algobase.h:230:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)'
  230 |     min(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/10/bits/stl_algobase.h:230:5: note:   template argument deduction/substitution failed:
race.cpp:34:43: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   34 |         m[sum].val = min(m[sum].val, depth);
      |                                           ^
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 race.cpp:1:
/usr/include/c++/10/bits/stl_algobase.h:278:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)'
  278 |     min(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/10/bits/stl_algobase.h:278:5: note:   template argument deduction/substitution failed:
race.cpp:34:43: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   34 |         m[sum].val = min(m[sum].val, depth);
      |                                           ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from race.cpp:1:
/usr/include/c++/10/bits/stl_algo.h:3468:5: note: candidate: 'template<class _Tp> constexpr _Tp std::min(std::initializer_list<_Tp>)'
 3468 |     min(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/10/bits/stl_algo.h:3468:5: note:   template argument deduction/substitution failed:
race.cpp:34:43: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   34 |         m[sum].val = min(m[sum].val, depth);
      |                                           ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from race.cpp:1:
/usr/include/c++/10/bits/stl_algo.h:3474:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::min(std::initializer_list<_Tp>, _Compare)'
 3474 |     min(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/10/bits/stl_algo.h:3474:5: note:   template argument deduction/substitution failed:
race.cpp:34:43: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   34 |         m[sum].val = min(m[sum].val, depth);
      |                                           ^
race.cpp:36:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   36 |     for (int i = 0; i < v[x].size(); ++i){
      |                     ~~^~~~~~~~~~~~~
race.cpp: In function 'int centr(int)':
race.cpp:54:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   54 |     for (int i = 0; i < v[x].size(); ++i){
      |                     ~~^~~~~~~~~~~~~
race.cpp: In function 'void solve(int, int)':
race.cpp:66:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   66 |     for (int i = 0; i < v[x].size(); ++i){
      |                     ~~^~~~~~~~~~~~~
race.cpp:72:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   72 |     for (int i = 0; i < s.size(); ++i)
      |                     ~~^~~~~~~~~~
race.cpp: In function 'void decompose(int, int)':
race.cpp:81:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   81 |     for (int i = 0; i < v[root].size(); ++i){
      |                     ~~^~~~~~~~~~~~~~~~