제출 #555680

#제출 시각아이디문제언어결과실행 시간메모리
555680Dan4Life경주 (Race) (IOI11_race)C++17
컴파일 에러
0 ms0 KiB
#include "race.h" #include <bits/stdc++.h> using namespace std; #define ll long long const int maxn = 100100; ll jmp[maxn][25], dis[maxn], depth[maxn], subtree[maxn], par[maxn]; int answ; set<pair<ll,ll>> adj[maxn]; set<int> sub[maxn]; vector<int> adj2[maxn]; multiset<pair<int,int>> S[maxn]; map<pair<int,int>,int> M; void dfs(int s, int p, int ok){ subtree[s]=1; if(ok){ depth[s] = (p==-1?0:depth[p]+1); dis[s] = (p==-1?0:dis[p]+M[{p,s}]); jmp[s][0] = p; } for(auto x : adj[s]){ int u = x.first; if(u==p) continue; dfs(u,s,ok), subtree[s]+=subtree[u]; } } int find_centroid(int s, int p, int sz){ for(auto u : adj[s]) if(u.first!=p and subtree[u.first]>sz/2) return find_centroid(u.first, s, sz); return s; } void make_centroid(int s, int p){ dfs(s,-1,0); int sz = subtree[s]; int centroid = find_centroid(s,-1,sz); par[centroid]=p; if(p!=-1) adj2[p].push_back(centroid); while(!adj[centroid].empty()){ int x = adj[centroid].begin()->first; adj[x].erase(adj[x].lower_bound({centroid,-1})); adj[centroid].erase(adj[centroid].begin()); make_centroid(x,centroid); } } int get_path(int x, int k){ for(int j = 0; j <= 18; j++) if(k&(1<<j) and x!=-1) x = jmp[x][j]; return x; } int lca(int a, int b){ if(a==b) return a; if(jmp[a][0]==jmp[b][0]) return jmp[a][0]; if(depth[a]>depth[b]) swap(a,b); if(depth[a]<depth[b]) return lca(a,get_path(b,depth[b]-depth[a])); for(int j = 18; j >= 0; j--) if(jmp[a][j]!=-1 and jmp[a][j]!=jmp[b][j]) return lca(jmp[a][j], jmp[b][j]); } ll dist(int a, int b){ return dis[a]+dis[b]-2*dis[lca(a,b)]; } int len(int a, int b){ return depth[a]+depth[b]-2*depth[lca(a,b)]; } void Merge(set<int> &S, set<int> &SS){ if(S.size()<SS.size()) S.swap(SS); for(auto u : SS) S.insert(u); } void DFS(int s, int p, int Anc, bool ok){ sub[s].insert(s); for(auto u : adj2[s]){ if(u==p) continue; DFS(u,s,s,0); for(auto w : sub[u]){ int X = Anc; if(X==-1) X = s; int D = dist(X,w); if(K-D==0) { answ = min(answ, len(X,w)); continue; } auto itr = S[X].lower_bound({K-D,-1}); if(itr!=S[X].end() and itr->first==K-D) answ = min(answ, len(X,w)+itr->second); } Merge(sub[s], sub[u]); DFS(u,s,s,1); } for(auto u : adj2[s]) if(u!=p) DFS(u,s,-1,0); if(Anc==-1) return; if(ok) S[Anc].insert({dist(Anc,s),len(Anc,s)}); else S[Anc].erase(S[Anc].find({dist(Anc,s),len(Anc,s)})); } int best_path(int N, int K, int H[][2], int L[]) { answ = N+1; for(int i = 0; i < N-1; i++) adj[++H[i][0]].insert({++H[i][1],L[i]}), adj[H[i][1]].insert({H[i][0],L[i]}), M[{H[i][0],H[i][1]}]=M[{H[i][1],H[i][0]}]=L[i]; memset(jmp, -1, sizeof(jmp)); dfs(1,-1,1); make_centroid(1,-1); for(int j = 1; j <= 18; j++) for(int i = 1; i <= N; i++) if(jmp[i][j-1]!=-1) jmp[i][j] = jmp[jmp[i][j-1]][j-1]; for(int i = 1; i <= N; i++){ int x = i; while(x!=-1){ S[x].insert({dist(i,x),len(i,x)}); x = par[x]; } } DFS(1,-1,-1,0); return (answ==N+1?-1:answ); }

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

race.cpp: In function 'void DFS(int, int, int, bool)':
race.cpp:85:16: error: 'K' was not declared in this scope
   85 |             if(K-D==0) { answ = min(answ, len(X,w)); continue; }
      |                ^
race.cpp:86:42: error: 'K' was not declared in this scope
   86 |             auto itr = S[X].lower_bound({K-D,-1});
      |                                          ^
race.cpp:86:49: error: no matching function for call to 'std::multiset<std::pair<int, int> >::lower_bound(<brace-enclosed initializer list>)'
   86 |             auto itr = S[X].lower_bound({K-D,-1});
      |                                                 ^
In file included from /usr/include/c++/10/set:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:87,
                 from race.cpp:2:
/usr/include/c++/10/bits/stl_multiset.h:810:7: note: candidate: 'std::multiset<_Key, _Compare, _Alloc>::iterator std::multiset<_Key, _Compare, _Alloc>::lower_bound(const key_type&) [with _Key = std::pair<int, int>; _Compare = std::less<std::pair<int, int> >; _Alloc = std::allocator<std::pair<int, int> >; std::multiset<_Key, _Compare, _Alloc>::iterator = std::_Rb_tree<std::pair<int, int>, std::pair<int, int>, std::_Identity<std::pair<int, int> >, std::less<std::pair<int, int> >, std::allocator<std::pair<int, int> > >::const_iterator; std::multiset<_Key, _Compare, _Alloc>::key_type = std::pair<int, int>]'
  810 |       lower_bound(const key_type& __x)
      |       ^~~~~~~~~~~
/usr/include/c++/10/bits/stl_multiset.h:810:35: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'const key_type&' {aka 'const std::pair<int, int>&'}
  810 |       lower_bound(const key_type& __x)
      |                   ~~~~~~~~~~~~~~~~^~~
/usr/include/c++/10/bits/stl_multiset.h:814:7: note: candidate: 'std::multiset<_Key, _Compare, _Alloc>::const_iterator std::multiset<_Key, _Compare, _Alloc>::lower_bound(const key_type&) const [with _Key = std::pair<int, int>; _Compare = std::less<std::pair<int, int> >; _Alloc = std::allocator<std::pair<int, int> >; std::multiset<_Key, _Compare, _Alloc>::const_iterator = std::_Rb_tree<std::pair<int, int>, std::pair<int, int>, std::_Identity<std::pair<int, int> >, std::less<std::pair<int, int> >, std::allocator<std::pair<int, int> > >::const_iterator; std::multiset<_Key, _Compare, _Alloc>::key_type = std::pair<int, int>]'
  814 |       lower_bound(const key_type& __x) const
      |       ^~~~~~~~~~~
/usr/include/c++/10/bits/stl_multiset.h:814:35: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'const key_type&' {aka 'const std::pair<int, int>&'}
  814 |       lower_bound(const key_type& __x) const
      |                   ~~~~~~~~~~~~~~~~^~~
/usr/include/c++/10/bits/stl_multiset.h:820:2: note: candidate: 'template<class _Kt> decltype ((std::multiset<_Key, _Compare, _Alloc>::iterator)(((std::multiset<_Key, _Compare, _Alloc>*)this)->std::multiset<_Key, _Compare, _Alloc>::_M_t._M_lower_bound_tr(__x))) std::multiset<_Key, _Compare, _Alloc>::lower_bound(const _Kt&) [with _Kt = _Kt; _Key = std::pair<int, int>; _Compare = std::less<std::pair<int, int> >; _Alloc = std::allocator<std::pair<int, int> >]'
  820 |  lower_bound(const _Kt& __x)
      |  ^~~~~~~~~~~
/usr/include/c++/10/bits/stl_multiset.h:820:2: note:   template argument deduction/substitution failed:
race.cpp:86:49: note:   couldn't deduce template parameter '_Kt'
   86 |             auto itr = S[X].lower_bound({K-D,-1});
      |                                                 ^
In file included from /usr/include/c++/10/set:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:87,
                 from race.cpp:2:
/usr/include/c++/10/bits/stl_multiset.h:826:2: note: candidate: 'template<class _Kt> decltype ((std::multiset<_Key, _Compare, _Alloc>::iterator)(((const std::multiset<_Key, _Compare, _Alloc>*)this)->std::multiset<_Key, _Compare, _Alloc>::_M_t._M_lower_bound_tr(__x))) std::multiset<_Key, _Compare, _Alloc>::lower_bound(const _Kt&) const [with _Kt = _Kt; _Key = std::pair<int, int>; _Compare = std::less<std::pair<int, int> >; _Alloc = std::allocator<std::pair<int, int> >]'
  826 |  lower_bound(const _Kt& __x) const
      |  ^~~~~~~~~~~
/usr/include/c++/10/bits/stl_multiset.h:826:2: note:   template argument deduction/substitution failed:
race.cpp:86:49: note:   couldn't deduce template parameter '_Kt'
   86 |             auto itr = S[X].lower_bound({K-D,-1});
      |                                                 ^
race.cpp: In function 'int lca(int, int)':
race.cpp:62:1: warning: control reaches end of non-void function [-Wreturn-type]
   62 | }
      | ^