Submission #671316

#TimeUsernameProblemLanguageResultExecution timeMemory
671316birthdaycakeRace (IOI11_race)C++17
Compilation error
0 ms0 KiB
#include "race.h"
#include <bits/stdc++.h>
using namespace std;

vector<pair<int,int>>adj[200001];
int dsu[200001],sz[200001];
int inbut[200001][2], ll[200001];
map<long long,int> store[200001];
long long vs[200001],sum[200001];
long long ans = INT_MAX, K;

int Find(int x){
    if(dsu[x] == x) return x;
    else return dsu[x] = Find(dsu[x]);
}

void Unite(int a, int b, int cur_k, int cur_depth){
    a = Find(a); b = Find(b);
    if(a > b) swap(a,b);
    sz[b] += sz[a];
    dsu[a] = b;
    for(auto s: store[a]){
        if(store[b][cur_k - s.first] != 0){
            ans = min(ans, s.second - cur_depth + store[b][cur_k - s.first] - cur_depth);
        }
    }
    for(auto s: store[a]){
        if(store[b][s.first] == 0 or store[b][s.first] > s.second){
            store[b][s.first] = s.second;
        }
    }
    if(store[b][cur_k] != 0) ans = min(ans, store[b][cur_k] - cur_depth);
}
void dfs(int x, int par, int depth){
    
    vs[x] = 1;
    int vv = 0;
    for(auto s: adj[x]){
        if(!vs[s.first]){
            sum[s.first] += s.second;
            sum[s.first] += sum[x];
            dfs(s.first, x, depth + 1);
            vv++;
        }
    }
    map<long long,int>p;
    p[sum[x]] = depth;
    store[x] = p;
    if(vv){
        for(auto s: adj[x]){
            if(s.first != par){
                Unite(x, s.first, 2 * sum[x] + K, depth);
            }
        }
    }
}
int best_path(int n, int k, int h[][2], int l[]){
    ans = INT_MAX;
    for(int i = 1; i <= n; i++){
        sum[i] = 0;
        vs[i] = 0;
        dsu[i] = i;
        sz[i] = 1;
        adj[i].clear();
    }
    for(int i = 0; i < n - 1; i++){
        h[i][0]++; h[i][1]++;
        adj[h[i][0]].push_back({h[i][1], l[i]});
        adj[h[i][1]].push_back({h[i][0], l[i]});
    }
    K = k;
    
    dfs(1, 0, 1);
    if(ans == INT_MAX) ans = -1;
  return ans;
}

Compilation message (stderr)

race.cpp: In function 'void Unite(int, int, int, int)':
race.cpp:24:88: error: no matching function for call to 'min(long long int&, int)'
   24 |             ans = min(ans, s.second - cur_depth + store[b][cur_k - s.first] - cur_depth);
      |                                                                                        ^
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 race.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:
race.cpp:24:88: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   24 |             ans = min(ans, s.second - cur_depth + store[b][cur_k - s.first] - cur_depth);
      |                                                                                        ^
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 race.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:
race.cpp:24:88: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   24 |             ans = min(ans, s.second - cur_depth + store[b][cur_k - s.first] - cur_depth);
      |                                                                                        ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from race.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:
race.cpp:24:88: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   24 |             ans = min(ans, s.second - cur_depth + store[b][cur_k - s.first] - cur_depth);
      |                                                                                        ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from race.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:
race.cpp:24:88: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   24 |             ans = min(ans, s.second - cur_depth + store[b][cur_k - s.first] - cur_depth);
      |                                                                                        ^
race.cpp:32:72: error: no matching function for call to 'min(long long int&, std::map<long long int, int>::mapped_type)'
   32 |     if(store[b][cur_k] != 0) ans = min(ans, store[b][cur_k] - cur_depth);
      |                                                                        ^
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 race.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:
race.cpp:32:72: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'std::map<long long int, int>::mapped_type' {aka 'int'})
   32 |     if(store[b][cur_k] != 0) ans = min(ans, store[b][cur_k] - cur_depth);
      |                                                                        ^
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 race.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:
race.cpp:32:72: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'std::map<long long int, int>::mapped_type' {aka 'int'})
   32 |     if(store[b][cur_k] != 0) ans = min(ans, store[b][cur_k] - cur_depth);
      |                                                                        ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from race.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:
race.cpp:32:72: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   32 |     if(store[b][cur_k] != 0) ans = min(ans, store[b][cur_k] - cur_depth);
      |                                                                        ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from race.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:
race.cpp:32:72: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   32 |     if(store[b][cur_k] != 0) ans = min(ans, store[b][cur_k] - cur_depth);
      |                                                                        ^