Submission #373948

#TimeUsernameProblemLanguageResultExecution timeMemory
373948duchungRace (IOI11_race)C++17
Compilation error
0 ms0 KiB
#define ii pair<int , int>

#include <bits/stdc++.h>
using namespace std;

const int N = 2e5 + 5;

int n , k , ans = 1e9;
int dist[N] , depth[N];
vector<ii> adj[N];
set<ii> S[N];

void dfs(int u , int p = -1)
{
    S[u].insert(make_pair(dist[u] , depth[u]));
    for (auto e : adj[u])
    {
        int v = e.first;
        int w = e.second;

        if (v == p) continue;

        dist[v] = dist[u] + w;
        depth[v] = depth[u] + 1;
        dfs(v , u);

        if (S[u].size() < S[v].size()) swap(S[u] , S[v]);
        for (auto x : S[v])
        {
            auto it = S[u].lower_bound(make_pair(k - x.first + 2 * dist[u] , 0));
            if (it != S[u].end() && it->first + x.first - 2 * dist[u] == k) ans = min(ans , it->second + x.second - 2 * depth[u]);
        }

        for (auto x : S[v])
        {
            S[u].insert(x);
        }
    }
}

int main()
{
    // freopen(".inp","r",stdin);
    // freopen(".out","w",stdout);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    cin >> n >> k;
    for (int i = 1 ; i < n ; ++i)
    {
        int u , v , w;
        cin >> u >> v >> w;
        ++u ; ++v;
        adj[u].push_back(ii(v , w));
        adj[v].push_back(ii(u , w));
    }

    dfs(1);
    cout << (ans == 1e9 ? -1 : ans);

}

Compilation message (stderr)

/tmp/ccHqamej.o: In function `main':
race.cpp:(.text.startup+0x0): multiple definition of `main'
/tmp/ccPDTf6j.o:grader.cpp:(.text.startup+0x0): first defined here
/tmp/ccPDTf6j.o: In function `main':
grader.cpp:(.text.startup+0x24): undefined reference to `best_path(int, int, int (*) [2], int*)'
collect2: error: ld returned 1 exit status