Submission #98947

# Submission time Handle Problem Language Result Execution time Memory
98947 2019-02-27T16:42:45 Z Hideo Race (IOI11_race) C++14
21 / 100
3000 ms 14624 KB
#include "race.h"
#include <bits/stdc++.h>
//#include "grader.cpp"

using namespace std;

#define mk make_pair
#define pb push_back
#define sc second
#define fr first
#define pii pair < int, int >
#define vii vector < pii >

const int MAXN = 2e5 + 7;
const int MAXK = 1e6 + 7;
const int INF = 1e9 + 7;

int ans = INF, k;
int st[MAXK], h[MAXN], del[MAXN];

vii g[MAXN];

void dfs (int v, int p = -1){
    h[v] = 1;
    for (pii to : g[v])
        if (to.fr != p && !del[to.fr])
            dfs(to.fr, v);
    if (p != -1)
        h[p] += h[v];
}

int centroid (int v){
    dfs(v);
    bool ok = false;
    int c = v, pr = 0;
    while (ok){
        ok = false;
        for (pii to : g[c]){
            if (to.fr != pr && !del[to.fr] && h[to.fr] * 2 >= h[v]){
                pr = c;
                c = to.fr;
                ok = true;
                break;
            }
        }
    }
    return c;
}

void findAns (int v, int p, int l, int d = 1){
    if (k > l && st[k - l])
        ans = min(ans, d + st[k - l]);
    if (k == l)
        ans = min(ans, d);
    if (l > k)
        return;
    for (pii to : g[v])
        if (to.fr != p && !del[to.fr])
            findAns (to.fr, v, l + to.sc, d + 1);
}

void upd (int v, int p, int l, int d = 1){
    if (k > l && st[l])
        st[l] = min(st[l], d);
    else if (k > l)
        st[l] = d;
    if (l > k)
        return;
    for (pii to : g[v])
        if (to.fr != p && !del[to.fr])
            upd(to.fr, v, l + to.sc, d + 1);
}

void calc (int v = 0){
    v = centroid(v);
    del[v] = 1;
    memset(st, 0, sizeof(st));
    for (pii to : g[v]){
        if (!del[to.fr]){
            findAns(to.fr, v, to.sc);
            upd(to.fr, v, to.sc);
        }
    }
    for (pii to : g[v])
        if (!del[to.fr])
            calc (to.fr);
}

int best_path(int N, int K, int H[][2], int L[])
{
    k = K;
    for (int i = 0; i < N - 1; i++){
        g[H[i][0]].pb(mk(H[i][1], L[i]));
        g[H[i][1]].pb(mk(H[i][0], L[i]));
    }
    calc();
    if (ans == INF)
        return -1;
    return ans;
}

# Verdict Execution time Memory Grader output
1 Correct 28 ms 8960 KB Output is correct
2 Correct 28 ms 8960 KB Output is correct
3 Correct 30 ms 8960 KB Output is correct
4 Correct 36 ms 8936 KB Output is correct
5 Correct 34 ms 8960 KB Output is correct
6 Correct 33 ms 8960 KB Output is correct
7 Correct 29 ms 9004 KB Output is correct
8 Correct 32 ms 8960 KB Output is correct
9 Correct 33 ms 8960 KB Output is correct
10 Correct 29 ms 8960 KB Output is correct
11 Correct 34 ms 8960 KB Output is correct
12 Correct 31 ms 8960 KB Output is correct
13 Correct 30 ms 8960 KB Output is correct
14 Correct 34 ms 8960 KB Output is correct
15 Correct 32 ms 8960 KB Output is correct
16 Correct 31 ms 9000 KB Output is correct
17 Correct 32 ms 8960 KB Output is correct
18 Correct 33 ms 8960 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 28 ms 8960 KB Output is correct
2 Correct 28 ms 8960 KB Output is correct
3 Correct 30 ms 8960 KB Output is correct
4 Correct 36 ms 8936 KB Output is correct
5 Correct 34 ms 8960 KB Output is correct
6 Correct 33 ms 8960 KB Output is correct
7 Correct 29 ms 9004 KB Output is correct
8 Correct 32 ms 8960 KB Output is correct
9 Correct 33 ms 8960 KB Output is correct
10 Correct 29 ms 8960 KB Output is correct
11 Correct 34 ms 8960 KB Output is correct
12 Correct 31 ms 8960 KB Output is correct
13 Correct 30 ms 8960 KB Output is correct
14 Correct 34 ms 8960 KB Output is correct
15 Correct 32 ms 8960 KB Output is correct
16 Correct 31 ms 9000 KB Output is correct
17 Correct 32 ms 8960 KB Output is correct
18 Correct 33 ms 8960 KB Output is correct
19 Correct 12 ms 8960 KB Output is correct
20 Correct 31 ms 8960 KB Output is correct
21 Correct 219 ms 9080 KB Output is correct
22 Correct 211 ms 9208 KB Output is correct
23 Correct 213 ms 9088 KB Output is correct
24 Correct 207 ms 9080 KB Output is correct
25 Correct 194 ms 9088 KB Output is correct
26 Correct 221 ms 9088 KB Output is correct
27 Correct 209 ms 9088 KB Output is correct
28 Correct 200 ms 9048 KB Output is correct
29 Correct 213 ms 9088 KB Output is correct
30 Correct 194 ms 9080 KB Output is correct
31 Correct 196 ms 9052 KB Output is correct
32 Correct 195 ms 9180 KB Output is correct
33 Correct 194 ms 9052 KB Output is correct
34 Correct 181 ms 9088 KB Output is correct
35 Correct 180 ms 9080 KB Output is correct
36 Correct 166 ms 9080 KB Output is correct
37 Correct 179 ms 9052 KB Output is correct
38 Correct 201 ms 8960 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 28 ms 8960 KB Output is correct
2 Correct 28 ms 8960 KB Output is correct
3 Correct 30 ms 8960 KB Output is correct
4 Correct 36 ms 8936 KB Output is correct
5 Correct 34 ms 8960 KB Output is correct
6 Correct 33 ms 8960 KB Output is correct
7 Correct 29 ms 9004 KB Output is correct
8 Correct 32 ms 8960 KB Output is correct
9 Correct 33 ms 8960 KB Output is correct
10 Correct 29 ms 8960 KB Output is correct
11 Correct 34 ms 8960 KB Output is correct
12 Correct 31 ms 8960 KB Output is correct
13 Correct 30 ms 8960 KB Output is correct
14 Correct 34 ms 8960 KB Output is correct
15 Correct 32 ms 8960 KB Output is correct
16 Correct 31 ms 9000 KB Output is correct
17 Correct 32 ms 8960 KB Output is correct
18 Correct 33 ms 8960 KB Output is correct
19 Execution timed out 3057 ms 14624 KB Time limit exceeded
20 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 28 ms 8960 KB Output is correct
2 Correct 28 ms 8960 KB Output is correct
3 Correct 30 ms 8960 KB Output is correct
4 Correct 36 ms 8936 KB Output is correct
5 Correct 34 ms 8960 KB Output is correct
6 Correct 33 ms 8960 KB Output is correct
7 Correct 29 ms 9004 KB Output is correct
8 Correct 32 ms 8960 KB Output is correct
9 Correct 33 ms 8960 KB Output is correct
10 Correct 29 ms 8960 KB Output is correct
11 Correct 34 ms 8960 KB Output is correct
12 Correct 31 ms 8960 KB Output is correct
13 Correct 30 ms 8960 KB Output is correct
14 Correct 34 ms 8960 KB Output is correct
15 Correct 32 ms 8960 KB Output is correct
16 Correct 31 ms 9000 KB Output is correct
17 Correct 32 ms 8960 KB Output is correct
18 Correct 33 ms 8960 KB Output is correct
19 Correct 12 ms 8960 KB Output is correct
20 Correct 31 ms 8960 KB Output is correct
21 Correct 219 ms 9080 KB Output is correct
22 Correct 211 ms 9208 KB Output is correct
23 Correct 213 ms 9088 KB Output is correct
24 Correct 207 ms 9080 KB Output is correct
25 Correct 194 ms 9088 KB Output is correct
26 Correct 221 ms 9088 KB Output is correct
27 Correct 209 ms 9088 KB Output is correct
28 Correct 200 ms 9048 KB Output is correct
29 Correct 213 ms 9088 KB Output is correct
30 Correct 194 ms 9080 KB Output is correct
31 Correct 196 ms 9052 KB Output is correct
32 Correct 195 ms 9180 KB Output is correct
33 Correct 194 ms 9052 KB Output is correct
34 Correct 181 ms 9088 KB Output is correct
35 Correct 180 ms 9080 KB Output is correct
36 Correct 166 ms 9080 KB Output is correct
37 Correct 179 ms 9052 KB Output is correct
38 Correct 201 ms 8960 KB Output is correct
39 Execution timed out 3057 ms 14624 KB Time limit exceeded
40 Halted 0 ms 0 KB -