Submission #441260

#TimeUsernameProblemLanguageResultExecution timeMemory
441260julian33Race (IOI11_race)C++14
Compilation error
0 ms0 KiB
#include <bits/stdc++.h> using namespace std; #ifdef LOCAL #define deb(...) logger(#__VA_ARGS__, __VA_ARGS__) template<typename ...Args> void logger(string vars, Args&&... values) { cerr<<vars<<" = "; string delim=""; (...,(cerr<<delim<<values,delim=", ")); cerr<<"\n"; } #else #define deb(...) logger(#__VA_ARGS__, __VA_ARGS__) template<typename ...Args> void logger(string vars, Args&&... values) {} #endif #define pb push_back #define sz(x) (int)(x.size()) typedef long long ll; typedef pair<int,int> pii; typedef pair<ll,ll> pll; template<typename T> inline void maxa(T& a,T b){a=max(a,b);} template<typename T> inline void mina(T& a,T b){a=min(a,b);} const int mxN=2e5+5,mxK=1e6+5; vector<pll> graph[mxN]; int seen[mxN],sub[mxN],ans=1e9,K,N; int mp[mxK]; vector<int> path; int dfs(int at,int p){ sub[at]=1; for(pll &u:graph[at]){ int i=u.first; int w=u.second; if(i==p || seen[i]) continue; sub[at]+=dfs(i,at); } return sub[at]; } int centroid(int at,int p,int s){ for(pll &u:graph[at]){ int i=u.first; int w=u.second; if(i==p || seen[i]) continue; if(2*sub[i]>=s) return centroid(i,at,s); } return at; } void solve(int at,int p,ll len,int filling,int h){ if(len>K) return; if(filling){ path.pb(len); mina(mp[len],h); } else{ mina(ans,mp[K-len]+h); } for(pll &u:graph[at]){ int i=u.first; int w=u.second; if(i==p || seen[i]) continue; solve(i,at,len+w,filling,h+1); } } void build(int at){ int s=dfs(at,-1); int cent=centroid(at,-1,s); mp[0]=0; for(pll &u:graph[cent]){ int i=u.first; int w=u.second; if(!seen[i]){ solve(i,cent,w,0,1); solve(i,cent,w,1,1); } } while(sz(path)){ mp[path.back()]=1e9; path.pop_back(); } seen[cent]=1; for(pll &u:graph[cent]){ int i=u.first; int w=u.second; if(!seen[i]) build(i); } } int best_path(int n,int k,int h[][2],int l[]){ N=n; K=k; for(int i=0;i<n-1;i++){ graph[h[i][0]].pb({graph[h[i][1]],l[i]}); graph[h[i][1]].pb({graph[h[i][0]],l[i]}); } fill(mp,mp+K+1,1e9); build(0); return ans==1e9?-1:ans; }

Compilation message (stderr)

race.cpp: In function 'int dfs(int, int)':
race.cpp:38:28: warning: unused variable 'w' [-Wunused-variable]
   38 |         int i=u.first; int w=u.second;
      |                            ^
race.cpp: In function 'int centroid(int, int, int)':
race.cpp:48:28: warning: unused variable 'w' [-Wunused-variable]
   48 |         int i=u.first; int w=u.second;
      |                            ^
race.cpp: In function 'void build(int)':
race.cpp:91:28: warning: unused variable 'w' [-Wunused-variable]
   91 |         int i=u.first; int w=u.second;
      |                            ^
race.cpp: In function 'int best_path(int, int, int (*)[2], int*)':
race.cpp:100:48: error: no matching function for call to 'std::vector<std::pair<long long int, long long int> >::push_back(<brace-enclosed initializer list>)'
  100 |         graph[h[i][0]].pb({graph[h[i][1]],l[i]});
      |                                                ^
In file included from /usr/include/c++/10/vector:67,
                 from /usr/include/c++/10/queue:61,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:86,
                 from race.cpp:1:
/usr/include/c++/10/bits/stl_vector.h:1187:7: note: candidate: 'void std::vector<_Tp, _Alloc>::push_back(const value_type&) [with _Tp = std::pair<long long int, long long int>; _Alloc = std::allocator<std::pair<long long int, long long int> >; std::vector<_Tp, _Alloc>::value_type = std::pair<long long int, long long int>]'
 1187 |       push_back(const value_type& __x)
      |       ^~~~~~~~~
/usr/include/c++/10/bits/stl_vector.h:1187:35: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'const value_type&' {aka 'const std::pair<long long int, long long int>&'}
 1187 |       push_back(const value_type& __x)
      |                 ~~~~~~~~~~~~~~~~~~^~~
/usr/include/c++/10/bits/stl_vector.h:1203:7: note: candidate: 'void std::vector<_Tp, _Alloc>::push_back(std::vector<_Tp, _Alloc>::value_type&&) [with _Tp = std::pair<long long int, long long int>; _Alloc = std::allocator<std::pair<long long int, long long int> >; std::vector<_Tp, _Alloc>::value_type = std::pair<long long int, long long int>]'
 1203 |       push_back(value_type&& __x)
      |       ^~~~~~~~~
/usr/include/c++/10/bits/stl_vector.h:1203:30: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'std::vector<std::pair<long long int, long long int> >::value_type&&' {aka 'std::pair<long long int, long long int>&&'}
 1203 |       push_back(value_type&& __x)
      |                 ~~~~~~~~~~~~~^~~
race.cpp:101:48: error: no matching function for call to 'std::vector<std::pair<long long int, long long int> >::push_back(<brace-enclosed initializer list>)'
  101 |         graph[h[i][1]].pb({graph[h[i][0]],l[i]});
      |                                                ^
In file included from /usr/include/c++/10/vector:67,
                 from /usr/include/c++/10/queue:61,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:86,
                 from race.cpp:1:
/usr/include/c++/10/bits/stl_vector.h:1187:7: note: candidate: 'void std::vector<_Tp, _Alloc>::push_back(const value_type&) [with _Tp = std::pair<long long int, long long int>; _Alloc = std::allocator<std::pair<long long int, long long int> >; std::vector<_Tp, _Alloc>::value_type = std::pair<long long int, long long int>]'
 1187 |       push_back(const value_type& __x)
      |       ^~~~~~~~~
/usr/include/c++/10/bits/stl_vector.h:1187:35: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'const value_type&' {aka 'const std::pair<long long int, long long int>&'}
 1187 |       push_back(const value_type& __x)
      |                 ~~~~~~~~~~~~~~~~~~^~~
/usr/include/c++/10/bits/stl_vector.h:1203:7: note: candidate: 'void std::vector<_Tp, _Alloc>::push_back(std::vector<_Tp, _Alloc>::value_type&&) [with _Tp = std::pair<long long int, long long int>; _Alloc = std::allocator<std::pair<long long int, long long int> >; std::vector<_Tp, _Alloc>::value_type = std::pair<long long int, long long int>]'
 1203 |       push_back(value_type&& __x)
      |       ^~~~~~~~~
/usr/include/c++/10/bits/stl_vector.h:1203:30: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'std::vector<std::pair<long long int, long long int> >::value_type&&' {aka 'std::pair<long long int, long long int>&&'}
 1203 |       push_back(value_type&& __x)
      |                 ~~~~~~~~~~~~~^~~