Submission #780102

#TimeUsernameProblemLanguageResultExecution timeMemory
780102CESxRhinoFactories (JOI14_factories)C++14
Compilation error
0 ms0 KiB
#include "factories.h" #include <bits/stdc++.h> #define ii pair<int,int> #define f first #define s second #define pb push_back #define ll long long #define endl '\n' using namespace std; int par[200005]; int depth[200005]; const int MAXN = 1e18; vector<ii> w[200005]; vector<pair<int,ll> > w2[200005]; int level[200005][33]; int First[200005]; int End[200005]; ll dist[200005]; int DFStime = 0; int color[200005]; int s[200005]; int t[200005]; ll mindist; void DFS(int u,int par) { First[u] = ++DFStime; for(int i = 1;i < 33;i++) { level[u][i] = level[level[u][i - 1]][i - 1]; } for(auto v:w[u]) { if(v.first == par) { continue; } dist[v.first] = dist[u] + v.second; DFS(v.first,u); } End[u] = DFStime; } bool check(int u,int v) { return (First[u] <= First[v] and End[u] <= End[v]); } int LCA(int u,int v) { if(check(u,v)) { return u; } if(check(v,u)) { return v; } for(int i = 32;i >= 0;i--) { if(!check(level[u][i],v)) { u = level[u][i]; } } return level[u][0]; } void Init(int n, int a[], int b[], int d[]) { for(int i = 0;i < n - 1;i++) { w[a[i]].pb({b[i],d[i]}), w[b[i]].pb({a[i],d[i]}); } DFS(0,0); } void edge(int u,int v) { if(u == v) { return; } ll d = abs(dist[u] - dist[v]); w2[u].push_back({v,d}); w2[v].push_back({u,d}); } int virtual_tree(vector<int> &nodes) { sort(nodes.begin(),nodes.end(),[](int &i, int &j){return (First[i] < First[j]);}); for(int i = (int) (nodes.size()) - 2;i >= 0;i--) { int res = LCA(nodes[i],nodes[i + 1]); nodes.push_back(res); } sort(nodes.begin(),nodes.end(),[](int &i, int &j){return (First[i] < First[j]);}); vector<int> s; s.push_back(nodes[0]); for(int i = 1;i < nodes.size();i++) { while(!check(s.back(),nodes[i])) { edge(s.back(),s[s.size() - 2]); s.pop_back(); } s.push_back(nodes[i]); } while(s.size() > 1) { edge(s.back(),s[s.size() - 2]); s.pop_back(); } return s[0]; } ii DFS2(int u,int par) { int min1 = MAXN; int min2 = MAXN; if(color[u] == 1) { min1 = 0; } else if(color[u] == 2) { min2 = 0; } for(auto v:w2[u]) { if(v.first != par) { ii tree = DFS2(v.first,u); min1 = min(min1,v.second + tree.first); min2 = min(min2,v.second + tree.second); } } mindist = min(mindist,min1 + min2); return {min1,min2}; } long long Query(int n, int x[], int m, int y[]) { vector<int> nodes; for(int i = 0;i < n;i++) { nodes.push_back(x[i]); color[x[i]] = 1; } for(int i = 0;i < n;i++) { nodes.push_back(y[i]); color[y[i]] = 2; } int r = virtual_tree(nodes); mindist = 1e18; DFS2(r,r); for(auto x:nodes) w2[x].clear(), color[x] = 0; return mindist; }

Compilation message (stderr)

factories.cpp:12:18: warning: overflow in conversion from 'double' to 'int' changes value from '1.0e+18' to '2147483647' [-Woverflow]
   12 | const int MAXN = 1e18;
      |                  ^~~~
factories.cpp: In function 'int virtual_tree(std::vector<int>&)':
factories.cpp:95:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   95 |  for(int i = 1;i < nodes.size();i++)
      |                ~~^~~~~~~~~~~~~~
factories.cpp: In function 'std::pair<int, int> DFS2(int, int)':
factories.cpp:128:41: error: no matching function for call to 'min(int&, long long int)'
  128 |    min1 = min(min1,v.second + tree.first);
      |                                         ^
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 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:128:41: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'long long int')
  128 |    min1 = min(min1,v.second + tree.first);
      |                                         ^
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 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:128:41: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'long long int')
  128 |    min1 = min(min1,v.second + tree.first);
      |                                         ^
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:128:41: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
  128 |    min1 = min(min1,v.second + tree.first);
      |                                         ^
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:128:41: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
  128 |    min1 = min(min1,v.second + tree.first);
      |                                         ^
factories.cpp:129:42: error: no matching function for call to 'min(int&, long long int)'
  129 |    min2 = min(min2,v.second + tree.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 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:129:42: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'long long int')
  129 |    min2 = min(min2,v.second + tree.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 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:129:42: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'long long int')
  129 |    min2 = min(min2,v.second + tree.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 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:129:42: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
  129 |    min2 = min(min2,v.second + tree.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 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:129:42: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
  129 |    min2 = min(min2,v.second + tree.second);
      |                                          ^
factories.cpp:132:35: error: no matching function for call to 'min(long long int&, int)'
  132 |  mindist = min(mindist,min1 + min2);
      |                                   ^
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 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:132:35: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
  132 |  mindist = min(mindist,min1 + min2);
      |                                   ^
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 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:132:35: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
  132 |  mindist = min(mindist,min1 + min2);
      |                                   ^
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:132:35: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
  132 |  mindist = min(mindist,min1 + min2);
      |                                   ^
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:132:35: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
  132 |  mindist = min(mindist,min1 + min2);
      |                                   ^