Submission #662538

# Submission time Handle Problem Language Result Execution time Memory
662538 2022-11-26T10:43:52 Z atigun Dreaming (IOI13_dreaming) C++11
Compilation error
0 ms 0 KB
#include<bits/stdc++.h>
#include"dreaming.h"

using namespace std;
typedef long long ll;

const int maxn = 1e5;
vector<vector<pair<int, int>>> g(maxn+5);
vector<bool> vis(maxn+5, false);
vector<ll> dt(maxn+5), ht(maxn+5, 0), group(maxn+5);
vector<multiset<ll>> S(maxn+5);

void dfs1(int v, int P){
  group[v] = P;
  vis[v] = 1;
  int maxi1 = 0, maxi2 = 0;
  for(pair<int, int> pp : g[v]){
    int u = pp.first, w = pp.second;
    if(vis[u])
      continue;
    dfs1(u, P);
    ht[v] = max(ht[v], ht[u]+w);
    if(ht[u]+w >= maxi1){
      maxi2 = maxi1, maxi1 = ht[u]+w;
    } else if(ht[u]+w >= maxi2){
      maxi2 = ht[u]+w;
    }
  }
  dt[v] = maxi1+maxi2;
}

void dfs2(int v, int p){
  vis[v] = 1;
  for(pair<int, int> pp : g[v]){
    int u = pp.first, w = pp.second;
    if(u == p)
      continue;
    S[v].insert(ht[u]+w);
  }
  for(pair<int, int> pp : g[v]){
    int u = pp.first, w = pp.second;
    if(u == p)
      continue;
    if(S[v].size() == 1){
      S[u].insert(w);
    } else if(!S[v].empty()){
      S[v].erase(S[v].find(ht[u]+w));
      int best = *--S[v].end();
      S[u].insert(best+w);
      S[v].insert(ht[u]+w);
    }
  }
  if(!S[v].empty())
    ht[v] = *--S[v].end();
  for(pair<int, int> pp : g[v]){
    int u = pp.first;
    if(vis[u])
      continue;
    dfs2(u, v);
  }
}

int travelTime(int N, int M, int L, int A[], int B[], int T[]){
  for(int i = 0; i < M; i++){
    g[A[i]].emplace_back(B[i], T[i]);
    g[B[i]].emplace_back(A[i], T[i]);
  }
  for(int i = 0; i < N; i++)
    if(!vis[i])
      dfs1(i, i);
  fill(vis.begin(), vis.end(), false);
  for(int i = 0; i < N; i++)
    if(!vis[i])
      dfs2(i, -1);
  long long ans = 0;
  for(int i = 0; i < N; i++)
    ans = max(ans, dt[i]);  
  vector<pair<int, int>> order;
  order.reserve(N);
  for(int i = 0; i < N; i++)
    order.emplace_back(ht[i], group[i]);
  sort(order.begin(), order.end());
  vector<int> G;
  G.reserve(N);
  vector<bool> used(N+5, false);
  for(int i = 0; i < N; i++){
    if(used[order[i].second])
      continue;
    G.push_back(order[i].first);
    used[order[i].second] = true;
  }
  int GN = G.size();
  sort(G.begin(), G.end(), [&](int n1, int n2){
    return n1 > n2;
  });
  if(GN >= 2)
    ans = max(ans, G[0]+G[1]+L);
  if(GN >= 3)
    ans=  max(ans, G[1]+G[2]+2*L);
  return ans;
}

/*int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m, l;
  cin >> n >> m >> l;
  int a[m], b[m], c[m];
  for(int i = 0; i < n; i++)
    cin >> a[i] >> b[i] >> c[i];
  cout << travelTime(n, m, l, a, b, c) << "\n";
}*/

Compilation message

dreaming.cpp: In function 'int travelTime(int, int, int, int*, int*, int*)':
dreaming.cpp:97:31: error: no matching function for call to 'max(long long int&, __gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type)'
   97 |     ans = max(ans, G[0]+G[1]+L);
      |                               ^
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 dreaming.cpp:1:
/usr/include/c++/10/bits/stl_algobase.h:254:5: note: candidate: 'template<class _Tp> const _Tp& std::max(const _Tp&, const _Tp&)'
  254 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/10/bits/stl_algobase.h:254:5: note:   template argument deduction/substitution failed:
dreaming.cpp:97:31: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'})
   97 |     ans = max(ans, G[0]+G[1]+L);
      |                               ^
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 dreaming.cpp:1:
/usr/include/c++/10/bits/stl_algobase.h:300:5: note: candidate: 'template<class _Tp, class _Compare> const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  300 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/10/bits/stl_algobase.h:300:5: note:   template argument deduction/substitution failed:
dreaming.cpp:97:31: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'})
   97 |     ans = max(ans, G[0]+G[1]+L);
      |                               ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from dreaming.cpp:1:
/usr/include/c++/10/bits/stl_algo.h:3480:5: note: candidate: 'template<class _Tp> _Tp std::max(std::initializer_list<_Tp>)'
 3480 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/10/bits/stl_algo.h:3480:5: note:   template argument deduction/substitution failed:
dreaming.cpp:97:31: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   97 |     ans = max(ans, G[0]+G[1]+L);
      |                               ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from dreaming.cpp:1:
/usr/include/c++/10/bits/stl_algo.h:3486:5: note: candidate: 'template<class _Tp, class _Compare> _Tp std::max(std::initializer_list<_Tp>, _Compare)'
 3486 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/10/bits/stl_algo.h:3486:5: note:   template argument deduction/substitution failed:
dreaming.cpp:97:31: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   97 |     ans = max(ans, G[0]+G[1]+L);
      |                               ^
dreaming.cpp:99:33: error: no matching function for call to 'max(long long int&, __gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type)'
   99 |     ans=  max(ans, G[1]+G[2]+2*L);
      |                                 ^
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 dreaming.cpp:1:
/usr/include/c++/10/bits/stl_algobase.h:254:5: note: candidate: 'template<class _Tp> const _Tp& std::max(const _Tp&, const _Tp&)'
  254 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/10/bits/stl_algobase.h:254:5: note:   template argument deduction/substitution failed:
dreaming.cpp:99:33: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'})
   99 |     ans=  max(ans, G[1]+G[2]+2*L);
      |                                 ^
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 dreaming.cpp:1:
/usr/include/c++/10/bits/stl_algobase.h:300:5: note: candidate: 'template<class _Tp, class _Compare> const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  300 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/10/bits/stl_algobase.h:300:5: note:   template argument deduction/substitution failed:
dreaming.cpp:99:33: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'})
   99 |     ans=  max(ans, G[1]+G[2]+2*L);
      |                                 ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from dreaming.cpp:1:
/usr/include/c++/10/bits/stl_algo.h:3480:5: note: candidate: 'template<class _Tp> _Tp std::max(std::initializer_list<_Tp>)'
 3480 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/10/bits/stl_algo.h:3480:5: note:   template argument deduction/substitution failed:
dreaming.cpp:99:33: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   99 |     ans=  max(ans, G[1]+G[2]+2*L);
      |                                 ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from dreaming.cpp:1:
/usr/include/c++/10/bits/stl_algo.h:3486:5: note: candidate: 'template<class _Tp, class _Compare> _Tp std::max(std::initializer_list<_Tp>, _Compare)'
 3486 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/10/bits/stl_algo.h:3486:5: note:   template argument deduction/substitution failed:
dreaming.cpp:99:33: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   99 |     ans=  max(ans, G[1]+G[2]+2*L);
      |                                 ^