Submission #1210871

#TimeUsernameProblemLanguageResultExecution timeMemory
1210871Born_To_LaughRace (IOI11_race)C++17
Compilation error
0 ms0 KiB
// Born_To_Laugh - Hughie Do
#include <bits/stdc++.h>
#define alle(Lotus) Lotus.begin(), Lotus.end()
using namespace std;
typedef long long ll;
[[maybe_unused]] const ll MOD = 998244353, INF = 1e9 + 7;

const int maxn = 2e5 + 5;
int n, k;
int ans = INF;
vector<int> sz(maxn, 1), bigchild(maxn, -1), dep(maxn, 0), dist(maxn, 0), mp(maxn, -1);
vector<int> adj[maxn];
map<pair<int,int>, int> wei;
vector<int> st;
void pre_dfs(int a, int par){
    for(auto &elm: adj[a]){
        if(elm == par)continue;
        dep[elm] = dep[a] + 1;
        dist[elm] = dist[a] + wei[{a, elm}];
        pre_dfs(elm, a);

        sz[a] += sz[elm];
        if(bigchild[a] == -1 || sz[bigchild[a]] < sz[elm])bigchild[a] = elm;
    }
}

//dist[1] + dist[2] - 2*dist[lca] = k
//dep[1] + dep[2] - 2*dep[lca];
void calc(int a, int par, int distlca, int deplca){
    int dist1 = k + 2 * distlca - dist[a];
    if(mp[dist1] != -1){
        ans = min(ans, mp[dist1] + dep[a] - 2*deplca);
    }
    for(auto &elm: adj[a]){
        if(elm == par)continue;
        calc(elm, a, distlca, deplca);
    }
}
void add(int a, int par, bool godown){
    if(mp[dist[a]] == -1){
        mp[dist[a]] = dep[a];
        st.push_back(dist[a]);
    }
    else mp[dist[a]] = min(mp[dist[a]], dep[a]);

    if(!godown)return;
    for(auto &elm: adj[a]){
        if(elm == par)continue;
        add(elm, a, 1);
    }
}

void clsdata(){
    for(auto &elm: st){
        mp[st] = -1;
    }
    st.clear();
}
void dfs(int a, int par){
    for(auto &elm: adj[a]){
        if(elm == par || elm == bigchild[a])continue;
        dfs(elm, a);
        clsdata();
    }

    if(bigchild[a] != -1) dfs(bigchild[a], a);

    for(auto &elm: adj[a]){
        if(elm == par || elm == bigchild[a])continue;
        calc(elm, a, dist[a], dep[a]);
        add(elm, a, 1);
    }

    int dist1 = k + dist[a];
    if(mp[dist1] != -1){
        ans = min(ans, mp[dist1] - dep[a]);
    }
    add(a, par, 0);
}
int best_path(int N, int K, int H[][2], int L[]){
    n = N;
    k = K;
    for(int i=0; i<n-1; ++i){
        int x = H[i][0], y = H[i][1];
        adj[x].push_back(y);
        adj[y].push_back(x);
        int w = L[i];
        wei[{x, y}] = w;
        wei[{y, x}] = w;
    }
    pre_dfs(0, -1);
    dfs(0, -1, 0);
    return (ans == INF?-1:ans);
}

Compilation message (stderr)

race.cpp: In function 'void clsdata()':
race.cpp:55:11: error: no match for 'operator[]' (operand types are 'std::vector<int>' and 'std::vector<int>')
   55 |         mp[st] = -1;
      |           ^
In file included from /usr/include/c++/11/vector:67,
                 from /usr/include/c++/11/functional:62,
                 from /usr/include/c++/11/pstl/glue_algorithm_defs.h:13,
                 from /usr/include/c++/11/algorithm:74,
                 from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:65,
                 from race.cpp:2:
/usr/include/c++/11/bits/stl_vector.h:1043:7: note: candidate: 'std::vector<_Tp, _Alloc>::reference std::vector<_Tp, _Alloc>::operator[](std::vector<_Tp, _Alloc>::size_type) [with _Tp = int; _Alloc = std::allocator<int>; std::vector<_Tp, _Alloc>::reference = int&; std::vector<_Tp, _Alloc>::size_type = long unsigned int]'
 1043 |       operator[](size_type __n) _GLIBCXX_NOEXCEPT
      |       ^~~~~~~~
/usr/include/c++/11/bits/stl_vector.h:1043:28: note:   no known conversion for argument 1 from 'std::vector<int>' to 'std::vector<int>::size_type' {aka 'long unsigned int'}
 1043 |       operator[](size_type __n) _GLIBCXX_NOEXCEPT
      |                  ~~~~~~~~~~^~~
/usr/include/c++/11/bits/stl_vector.h:1061:7: note: candidate: 'std::vector<_Tp, _Alloc>::const_reference std::vector<_Tp, _Alloc>::operator[](std::vector<_Tp, _Alloc>::size_type) const [with _Tp = int; _Alloc = std::allocator<int>; std::vector<_Tp, _Alloc>::const_reference = const int&; std::vector<_Tp, _Alloc>::size_type = long unsigned int]'
 1061 |       operator[](size_type __n) const _GLIBCXX_NOEXCEPT
      |       ^~~~~~~~
/usr/include/c++/11/bits/stl_vector.h:1061:28: note:   no known conversion for argument 1 from 'std::vector<int>' to 'std::vector<int>::size_type' {aka 'long unsigned int'}
 1061 |       operator[](size_type __n) const _GLIBCXX_NOEXCEPT
      |                  ~~~~~~~~~~^~~
race.cpp: In function 'int best_path(int, int, int (*)[2], int*)':
race.cpp:92:8: error: too many arguments to function 'void dfs(int, int)'
   92 |     dfs(0, -1, 0);
      |     ~~~^~~~~~~~~~
race.cpp:59:6: note: declared here
   59 | void dfs(int a, int par){
      |      ^~~