Submission #683156

#TimeUsernameProblemLanguageResultExecution timeMemory
683156LucaGregFactories (JOI14_factories)C++17
Compilation error
0 ms0 KiB
#include <bits/stdc++.h> #include "factories.h" using namespace std; #define pb push_back #define ll long long int #define ff first #define ss second const ll INF = 1000000000000000000; vector<int> adj[100010]; vector<int> weight[100010]; bool removed[100010]; int sub[100010]; int paiCentroid[100010]; pair<ll, int> minFactoryDist[100010]; int ancestor[100010][30]; ll nivel[100010]; int tin[100010], tout[100010]; int h = 0; int t = 0; int curQuery = 0; void dfsInit(int cur, int pai){ sub[cur] = 1; for(int i=0;i<(int)adj[cur].size();i++){ int viz = adj[cur][i]; if(removed[viz]) continue; if(viz==pai) continue; dfsInit(viz, cur); sub[cur] += viz; } } int findCentroid(int cur, int pai, int size){ for(int i=0;i<(int)adj[cur].size();i++){ int viz = adj[cur][i]; if(removed[viz]) continue; if(viz==pai) continue; if(sub[viz]>size/2) return findCentroid(viz, cur, size); } return cur; } void createCentroidTree(int cur, int centroidPai){ dfsInit(cur, cur); int centroid = findCentroid(cur, cur, sub[cur]); paiCentroid[centroid] = centroidPai; removed[centroid] = true; for(int i=0;i<(int)adj[centroid].size();i++){ int viz = ad[centroid][i]; if(removed[viz]) continue; createCentroidTree(viz, centroid); } } void dfs(int cur, int pai){ t++; tin[cur] = t; ancestor[cur][0] = pai; for(int i=1;i<=h;i++) ancestor[cur][i] = ancestor[ancestor[cur][i-1]][i-1]; for(int i=0;i<(int)adj[cur].size();i++){ int viz = adj[cur][i]; int w = weight[cur][i]; if(viz==pai) continue; nivel[viz] = nivel[pai] + w; dfs(viz, cur); } tout[cur] = t; } bool isAncestor(int a, int b){ return tin[a]<=tin[b] && tout[b]<=tout[a]; } int lca(int a, int b){ if(isAncestor(a, b)) return a; if(isAncestor(b, a)) return b; for(int i=h;i>=0;i--) if(!isAncestor(ancestor[a][i], b)) a = ancestor[a][i]; return ancestor[a][0]; } ll calculaDist(int a, int b){ int lca_ = lca(a, b); ll resp = abs(nivel[lca_] - nivel[a]) + abs(nivel[lca_] - nivel[b]); return resp; } void update(int v){ int cur = v; while(cur!=-1){ ll distancia = calculaDist(v, cur); if(minFactoryDist[cur].ss<curQuery){ minFactoryDist[cur].ff = distancia minFactoryDist[cur].ss = curQuery; }else{ minFactoryDist[cur].ff = min(minFactoryDist[cur], distancia); } cur = paiCentroid[cur]; } } ll calculaMinFactoryDist(int v){ int cur = v; ll resp = INF; while(cur!=-1){ ll distancia = calculaDist(v, cur); if(minFactoryDist[cur].ss<curQuery) continue; resp = min(resp, distancia + minFactoryDist[cur].ff); cur = paiCentroid[cur]; } return resp; } void Init(int N, int A[], int B[], int D[]){ nivel[0] = 0; dfs(0, 0); h = ceil(log2(N)); for(int i=0;i<n-1;i++){ int a = A[i], b = B[i], d = D[i]; adj[a].pb(b); weight[a].pb(d); adj[b].pb(a); weight[b].pb(d); } createCentroidTree(0, -1); } long long Query(int S, int X[], int T, int Y[]){ curQuery++; for(int i=0;i<S;i++) update(X[i]); ll resp = INF; for(int i=0;i<T;i++) resp = min(resp, calculaMinFactoryDist(Y[i])); return resp; }

Compilation message (stderr)

factories.cpp: In function 'void createCentroidTree(int, int)':
factories.cpp:61:19: error: 'ad' was not declared in this scope; did you mean 'adj'?
   61 |         int viz = ad[centroid][i];
      |                   ^~
      |                   adj
factories.cpp: In function 'void update(int)':
factories.cpp:105:47: error: expected ';' before 'minFactoryDist'
  105 |             minFactoryDist[cur].ff = distancia
      |                                               ^
      |                                               ;
  106 |             minFactoryDist[cur].ss = curQuery;
      |             ~~~~~~~~~~~~~~                     
factories.cpp:108:72: error: no matching function for call to 'min(std::pair<long long int, int>&, long long int&)'
  108 |             minFactoryDist[cur].ff = min(minFactoryDist[cur], distancia);
      |                                                                        ^
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 factories.cpp:2:
/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:
factories.cpp:108:72: note:   deduced conflicting types for parameter 'const _Tp' ('std::pair<long long int, int>' and 'long long int')
  108 |             minFactoryDist[cur].ff = min(minFactoryDist[cur], distancia);
      |                                                                        ^
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 factories.cpp:2:
/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:
factories.cpp:108:72: note:   deduced conflicting types for parameter 'const _Tp' ('std::pair<long long int, int>' and 'long long int')
  108 |             minFactoryDist[cur].ff = min(minFactoryDist[cur], distancia);
      |                                                                        ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from factories.cpp:2:
/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:
factories.cpp:108:72: note:   'std::pair<long long int, int>' is not derived from 'std::initializer_list<_Tp>'
  108 |             minFactoryDist[cur].ff = min(minFactoryDist[cur], distancia);
      |                                                                        ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from factories.cpp:2:
/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:
factories.cpp:108:72: note:   'std::pair<long long int, int>' is not derived from 'std::initializer_list<_Tp>'
  108 |             minFactoryDist[cur].ff = min(minFactoryDist[cur], distancia);
      |                                                                        ^
factories.cpp: In function 'void Init(int, int*, int*, int*)':
factories.cpp:130:19: error: 'n' was not declared in this scope
  130 |     for(int i=0;i<n-1;i++){
      |                   ^