제출 #543860

#제출 시각아이디문제언어결과실행 시간메모리
543860AJ00경주 (Race) (IOI11_race)C++14
컴파일 에러
0 ms0 KiB
#include <bits/stdc++.h> #include "race.h" using namespace std; //#define ll long long #define ll long long const ll MAXN = 200001; const ll LOGN = 20; vector<vector<pair<ll,ll>>> adj(MAXN); ll depth[MAXN],par[MAXN][LOGN],weight[MAXN][LOGN]; pair<ll,ll> lca(ll x, ll y){ ll X = x, Y = y; if (depth[X] < depth[Y]){ swap(x,y); swap(X,Y); } ll dh = depth[x]-depth[y]; ll totw = 0; for (ll i = LOGN-1; i >= 0; i--){ if (dh&(1<<i)){ totw += weight[x][i]; x = par[x][i]; } } if (x == y){ return {totw, depth[X]-depth[Y]}; } ll lvl = 0; for (ll i = LOGN; i >= 0; i--){ if (par[x][i] != par[y][i]){ totw += weight[x][i]; totw += weight[y][i]; lvl += (1<<i); x = par[x][i]; y = par[y][i]; } } totw += weight[x][0]; totw += weight[y][0]; lvl += 1; lvl *= 2; return {totw,lvl+depth[X]-depth[Y]}; } void dfs(ll x, ll h = 0, ll p= 0, ll w = 0){ depth[x] = h; par[x][0] = p; weight[x][0] = w; for (ll i = 1; i < LOGN; i++){ par[x][i] = par[par[x][i-1]][i-1]; weight[x][i] = weight[x][i-1] + weight[par[x][i-1]][i-1]; } for (auto ch: adj[x]){ ll t = ch.first; ll wt = ch.second; if (t != p){ dfs(t,h+1,x,wt); } } } int best_path(int N,int K,int H[][2],int L[]){ for (ll i = 0; i < N-1; i++){ adj[H[i][0]].push_back({H[i][1],L[i]}); adj[H[i][1]].push_back({H[i][0],L[i]}); } dfs(0); int ans = N; for (ll i = 0; i < N; i++){ for (ll j = i+1; j < N; j++){ pair<ll,ll> l = lca(i,j); if (l.first == K){ // cout << i << " " << j << " " << depth[i] << " " << depth[j] << "\n"; ans = min(ans,l.second); } } } ans -= (ans == N ? N+1 : 0); return ans; }

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

race.cpp: In function 'int best_path(int, int, int (*)[2], int*)':
race.cpp:71:39: error: no matching function for call to 'min(int&, long long int&)'
   71 |                 ans = min(ans,l.second);
      |                                       ^
In file included from /usr/include/c++/10/bits/char_traits.h:39,
                 from /usr/include/c++/10/ios:40,
                 from /usr/include/c++/10/istream:38,
                 from /usr/include/c++/10/sstream:38,
                 from /usr/include/c++/10/complex:45,
                 from /usr/include/c++/10/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:54,
                 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:71:39: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'long long int')
   71 |                 ans = min(ans,l.second);
      |                                       ^
In file included from /usr/include/c++/10/bits/char_traits.h:39,
                 from /usr/include/c++/10/ios:40,
                 from /usr/include/c++/10/istream:38,
                 from /usr/include/c++/10/sstream:38,
                 from /usr/include/c++/10/complex:45,
                 from /usr/include/c++/10/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:54,
                 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:71:39: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'long long int')
   71 |                 ans = min(ans,l.second);
      |                                       ^
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:71:39: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   71 |                 ans = min(ans,l.second);
      |                                       ^
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:71:39: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   71 |                 ans = min(ans,l.second);
      |                                       ^