Submission #637822

#TimeUsernameProblemLanguageResultExecution timeMemory
637822ertoRace (IOI11_race)C++17
Compilation error
0 ms0 KiB
#include <bits/stdc++.h>
#include "race.h"
typedef long long int ll;
#define INF (int)(1e9 + 7)
#define INF2 998244353
#define N (ll)(2e5 + 5)
using namespace std;
#define int ll
#define lsb(x) (x & (-x))

int n, k, g;
int ans = INF;
vector<pair<int, int>> v[N];
set<pair<int, int>> s[N];
int d[N];
int dis[N];

int h[N][2], l[N];


void dfs(int x, int p){
    for(auto u : v[x]){
        if(u.first != p){
            d[u.first] = d[x] + 1;
            dis[u.first] = dis[x] + u.second;
            dfs(u.first, x);
        }
    }

    s[x].insert({dis[x], d[x]});

    for(auto u : v[x]){
        if(u.first != p){
            if(s[x].size() < s[u.first].size()){
                swap(s[x], s[u.first]);
            }

            for(auto j : s[u.first]){
                if(x == 0){
                    cout << j.first << '\n';
                }
                g = k - (j.first - dis[x]) + dis[x];
                auto it = s[x].lower_bound(make_pair(g, 0ll));
                if(it != s[x].end() && it->first == g){
                    ans = min(ans, j.second + it->second - 2 * d[x]);
                }
                s[x].insert(j);
            }
        }
    }
    s[x].insert({0, d[x]});
}

int best_path(int nn, int K, int H[][2], int L[]){
    n = nn;
    for(int i=0; i<n-1; i++){
        v[h[i][0]].push_back({h[i][1], L[i]});
        v[h[i][1]].push_back({h[i][0], L[i]});
    }

    k=K;
    dfs(0, -1);
    if(ans == INF)return - 1;
    return ans;
}

Compilation message (stderr)

/usr/bin/ld: /tmp/ccu8RMGN.o: in function `main':
grader.cpp:(.text.startup+0x28): undefined reference to `best_path(int, int, int (*) [2], int*)'
collect2: error: ld returned 1 exit status