Submission #543835

#TimeUsernameProblemLanguageResultExecution timeMemory
543835AJ00Race (IOI11_race)C++14
Compilation error
0 ms0 KiB
#include <bits/stdc++.h>
#include "race.h"
using namespace std;
#define int long long 
const int MAXN = 200001;
const int LOGN = 20;
vector<vector<pair<int,int>>> adj(MAXN);
int depth[MAXN],par[MAXN][LOGN],weight[MAXN][LOGN];
pair<int,int> lca(int x, int y){
    int X = x, Y = y;
    if (depth[X] < depth[Y]){
        swap(x,y);
        swap(X,Y);
    }
    int dh = depth[x]-depth[y];
    int totw = 0;
    for (int i = LOGN-1; i >= 0; i--){
        if (dh&(1<<i)){
            totw += weight[x][i];
            x = par[x][i];
        }
    }
    if (x == y){
        return {totw, depth[X]-depth[Y]};
    }
    int lvl = 0;
    for (int i = LOGN; i >= 0; i--){
        if (par[x][i] != par[y][i]){
            totw += weight[x][i];
            totw += weight[y][i];
            lvl += (1<<i);
            x = par[x][i];
            y = par[y][i];
        }
    }
    totw += weight[x][0];
    totw += weight[y][0];
    lvl += 1;
    lvl *= 2;
    return {totw,lvl+depth[X]-depth[Y]};
}
void dfs(int x, int h = 0, int p= 0, int w = 0){
    depth[x] = h;
    par[x][0] = p;
    weight[x][0] = w;
    for (int i = 1; i < LOGN; i++){
        par[x][i] = par[par[x][i-1]][i-1];
        weight[x][i] = weight[x][i-1] + weight[par[x][i-1]][i-1];
    }
    for (auto ch: adj[x]){
        int t = ch.first;
        int wt = ch.second;
        if (t != p){
            dfs(t,h+1,x,wt);
        }
    }
}
int best_path(int N, int K, vector<vector<int>> H, vector<int> L[]){
    for (int i = 0; i < N-1; i++){
        adj[H[i][0]].push_back({H[i][1],L[i]});
        adj[H[i][1]].push_back({H[i][0],L[i]});
    }
    dfs(0);
    int ans = N;
    for (int i = 0; i < N; i++){
        for (int j = i+1; j < N; j++){
            pair<int,int> l = lca(i,j);
            if (l.first == K){
               // cout << i << " " << j << " " << depth[i] << " " << depth[j] << "\n";
                ans = min(ans,l.second);
            }
        }
    }
    ans -= (ans == N ? N+1 : 0);
    return ans;
}

Compilation message (stderr)

race.cpp: In function 'long long int best_path(long long int, long long int, std::vector<std::vector<long long int> >, std::vector<long long int>*)':
race.cpp:60:46: error: no matching function for call to 'std::vector<std::pair<long long int, long long int> >::push_back(<brace-enclosed initializer list>)'
   60 |         adj[H[i][0]].push_back({H[i][1],L[i]});
      |                                              ^
In file included from /usr/include/c++/10/vector:67,
                 from /usr/include/c++/10/queue:61,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:86,
                 from race.cpp:1:
/usr/include/c++/10/bits/stl_vector.h:1187:7: note: candidate: 'void std::vector<_Tp, _Alloc>::push_back(const value_type&) [with _Tp = std::pair<long long int, long long int>; _Alloc = std::allocator<std::pair<long long int, long long int> >; std::vector<_Tp, _Alloc>::value_type = std::pair<long long int, long long int>]'
 1187 |       push_back(const value_type& __x)
      |       ^~~~~~~~~
/usr/include/c++/10/bits/stl_vector.h:1187:35: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'const value_type&' {aka 'const std::pair<long long int, long long int>&'}
 1187 |       push_back(const value_type& __x)
      |                 ~~~~~~~~~~~~~~~~~~^~~
/usr/include/c++/10/bits/stl_vector.h:1203:7: note: candidate: 'void std::vector<_Tp, _Alloc>::push_back(std::vector<_Tp, _Alloc>::value_type&&) [with _Tp = std::pair<long long int, long long int>; _Alloc = std::allocator<std::pair<long long int, long long int> >; std::vector<_Tp, _Alloc>::value_type = std::pair<long long int, long long int>]'
 1203 |       push_back(value_type&& __x)
      |       ^~~~~~~~~
/usr/include/c++/10/bits/stl_vector.h:1203:30: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'std::vector<std::pair<long long int, long long int> >::value_type&&' {aka 'std::pair<long long int, long long int>&&'}
 1203 |       push_back(value_type&& __x)
      |                 ~~~~~~~~~~~~~^~~
race.cpp:61:46: error: no matching function for call to 'std::vector<std::pair<long long int, long long int> >::push_back(<brace-enclosed initializer list>)'
   61 |         adj[H[i][1]].push_back({H[i][0],L[i]});
      |                                              ^
In file included from /usr/include/c++/10/vector:67,
                 from /usr/include/c++/10/queue:61,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:86,
                 from race.cpp:1:
/usr/include/c++/10/bits/stl_vector.h:1187:7: note: candidate: 'void std::vector<_Tp, _Alloc>::push_back(const value_type&) [with _Tp = std::pair<long long int, long long int>; _Alloc = std::allocator<std::pair<long long int, long long int> >; std::vector<_Tp, _Alloc>::value_type = std::pair<long long int, long long int>]'
 1187 |       push_back(const value_type& __x)
      |       ^~~~~~~~~
/usr/include/c++/10/bits/stl_vector.h:1187:35: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'const value_type&' {aka 'const std::pair<long long int, long long int>&'}
 1187 |       push_back(const value_type& __x)
      |                 ~~~~~~~~~~~~~~~~~~^~~
/usr/include/c++/10/bits/stl_vector.h:1203:7: note: candidate: 'void std::vector<_Tp, _Alloc>::push_back(std::vector<_Tp, _Alloc>::value_type&&) [with _Tp = std::pair<long long int, long long int>; _Alloc = std::allocator<std::pair<long long int, long long int> >; std::vector<_Tp, _Alloc>::value_type = std::pair<long long int, long long int>]'
 1203 |       push_back(value_type&& __x)
      |       ^~~~~~~~~
/usr/include/c++/10/bits/stl_vector.h:1203:30: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'std::vector<std::pair<long long int, long long int> >::value_type&&' {aka 'std::pair<long long int, long long int>&&'}
 1203 |       push_back(value_type&& __x)
      |                 ~~~~~~~~~~~~~^~~