Submission #519010

#TimeUsernameProblemLanguageResultExecution timeMemory
519010fabijan_cikacRace (IOI11_race)C++17
Compilation error
0 ms0 KiB
#include <bits/stdc++.h>

using namespace std;

typedef pair<int, int> pp;

const int MAXN = 2 * 1e5 + 100;
const int INF = 1e8;

struct mapa{
    int val = INF;
};

int n; int k;
vector<pp> v[MAXN];
int p[MAXN] = { 0 };
int vel[MAXN] = { 0 };
mapa m[INF];
vector<int> s;
int sol = INF;
int cnt = 0;

int dfs(int x, int depth, int sum, int val, int k){
    p[x] = 1;
    if (val == 1 && sum <= k){
        int zb = depth + m[k - sum].val - 1;
        sol = min(sol, zb);
    }
    else if (val == 2 && sum <= k){
        s.push_back(sum);
        m[sum].val = min(m[sum].val, depth);
    }
    for (int i = 0; i < v[x].size(); ++i){
        int y = v[x][i].first;
        if (!p[y]){
            int rt = dfs(y, depth + 1, sum + v[x][i].second, val, k);
            if (val == 0)
                vel[x] += rt;
        }
    }
    p[x] = 0;
    if (val == 0)
        return vel[x];
    return 0;
}

int centr(int x){
    pp maks = {-1, -1}; m[0].val = 1;
    for (int i = 0; i < v[x].size(); ++i){
        int y = v[x][i].first;
        if (!p[y] && vel[y] > maks.second)
            maks = {y, vel[y]};
    }
    if (maks.second <= cnt / 2)
        return x;
    return maks.first;
}

void solve(int x, int K){
    s.clear();
    for (int i = 0; i < v[x].size(); ++i){
        int y = v[x][i].first;
        if (!p[y]){
            dfs(y, 2, v[x][i].second, 1, K); dfs(y, 2, v[x][i].second, 2, K);
        }
    }
    while (!s.empty()){
    	m[s.back()].val = INF; s.pop_back();
	}
	return;
}

void decompose(int x, int K){
    cnt = 0; dfs(x, 1, 0, 0, K); cnt = vel[x];
    int root = centr(x); p[root] = 1;
    solve(root, K);
    for (int i = 0; i < v[root].size(); ++i){
        int y = v[root][i].first;
        if (!p[y]) decompose(y, K);
    }
}

int best_path(int N, int K, int H[MAXN][2], int L[MAXN]){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    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]});
    }
    decompose(0, K);
    if (sol == INF)
        return -1;
    else return (sol - 1);

    return 0;
}

Compilation message (stderr)

Compilation timeout while compiling race