Submission #98997

# Submission time Handle Problem Language Result Execution time Memory
98997 2019-02-28T03:24:11 Z Hideo Race (IOI11_race) C++14
100 / 100
890 ms 33400 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, t;
int st[MAXK], mt[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 = true;
    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 && mt[k - l] == t)
        ans = min(ans, d + st[k - l]);
    else 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 && mt[l] != t){
        mt[l] = t;
        st[l] = d;
    }
    else if (k > l)
        st[l] = min(d, st[l]);
    else
        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;
    t++;
    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 6 ms 5120 KB Output is correct
2 Correct 7 ms 5120 KB Output is correct
3 Correct 7 ms 5120 KB Output is correct
4 Correct 6 ms 4992 KB Output is correct
5 Correct 7 ms 4992 KB Output is correct
6 Correct 6 ms 5120 KB Output is correct
7 Correct 7 ms 4992 KB Output is correct
8 Correct 8 ms 4992 KB Output is correct
9 Correct 6 ms 5144 KB Output is correct
10 Correct 8 ms 4992 KB Output is correct
11 Correct 7 ms 4992 KB Output is correct
12 Correct 6 ms 4992 KB Output is correct
13 Correct 6 ms 5092 KB Output is correct
14 Correct 7 ms 5120 KB Output is correct
15 Correct 7 ms 4992 KB Output is correct
16 Correct 7 ms 5120 KB Output is correct
17 Correct 7 ms 5120 KB Output is correct
18 Correct 8 ms 5120 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 5120 KB Output is correct
2 Correct 7 ms 5120 KB Output is correct
3 Correct 7 ms 5120 KB Output is correct
4 Correct 6 ms 4992 KB Output is correct
5 Correct 7 ms 4992 KB Output is correct
6 Correct 6 ms 5120 KB Output is correct
7 Correct 7 ms 4992 KB Output is correct
8 Correct 8 ms 4992 KB Output is correct
9 Correct 6 ms 5144 KB Output is correct
10 Correct 8 ms 4992 KB Output is correct
11 Correct 7 ms 4992 KB Output is correct
12 Correct 6 ms 4992 KB Output is correct
13 Correct 6 ms 5092 KB Output is correct
14 Correct 7 ms 5120 KB Output is correct
15 Correct 7 ms 4992 KB Output is correct
16 Correct 7 ms 5120 KB Output is correct
17 Correct 7 ms 5120 KB Output is correct
18 Correct 8 ms 5120 KB Output is correct
19 Correct 7 ms 5120 KB Output is correct
20 Correct 7 ms 4992 KB Output is correct
21 Correct 7 ms 5120 KB Output is correct
22 Correct 13 ms 10112 KB Output is correct
23 Correct 13 ms 9472 KB Output is correct
24 Correct 16 ms 10880 KB Output is correct
25 Correct 13 ms 8576 KB Output is correct
26 Correct 12 ms 7808 KB Output is correct
27 Correct 3 ms 5120 KB Output is correct
28 Correct 9 ms 6656 KB Output is correct
29 Correct 11 ms 7680 KB Output is correct
30 Correct 11 ms 7936 KB Output is correct
31 Correct 12 ms 8832 KB Output is correct
32 Correct 13 ms 8832 KB Output is correct
33 Correct 14 ms 10340 KB Output is correct
34 Correct 14 ms 9472 KB Output is correct
35 Correct 17 ms 11008 KB Output is correct
36 Correct 16 ms 11520 KB Output is correct
37 Correct 12 ms 8960 KB Output is correct
38 Correct 11 ms 7424 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 5120 KB Output is correct
2 Correct 7 ms 5120 KB Output is correct
3 Correct 7 ms 5120 KB Output is correct
4 Correct 6 ms 4992 KB Output is correct
5 Correct 7 ms 4992 KB Output is correct
6 Correct 6 ms 5120 KB Output is correct
7 Correct 7 ms 4992 KB Output is correct
8 Correct 8 ms 4992 KB Output is correct
9 Correct 6 ms 5144 KB Output is correct
10 Correct 8 ms 4992 KB Output is correct
11 Correct 7 ms 4992 KB Output is correct
12 Correct 6 ms 4992 KB Output is correct
13 Correct 6 ms 5092 KB Output is correct
14 Correct 7 ms 5120 KB Output is correct
15 Correct 7 ms 4992 KB Output is correct
16 Correct 7 ms 5120 KB Output is correct
17 Correct 7 ms 5120 KB Output is correct
18 Correct 8 ms 5120 KB Output is correct
19 Correct 244 ms 10744 KB Output is correct
20 Correct 232 ms 10716 KB Output is correct
21 Correct 260 ms 10744 KB Output is correct
22 Correct 215 ms 10960 KB Output is correct
23 Correct 123 ms 11000 KB Output is correct
24 Correct 99 ms 10744 KB Output is correct
25 Correct 251 ms 12712 KB Output is correct
26 Correct 111 ms 16120 KB Output is correct
27 Correct 312 ms 19432 KB Output is correct
28 Correct 536 ms 27640 KB Output is correct
29 Correct 590 ms 27000 KB Output is correct
30 Correct 291 ms 19356 KB Output is correct
31 Correct 307 ms 19320 KB Output is correct
32 Correct 318 ms 19448 KB Output is correct
33 Correct 429 ms 18300 KB Output is correct
34 Correct 411 ms 19064 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 5120 KB Output is correct
2 Correct 7 ms 5120 KB Output is correct
3 Correct 7 ms 5120 KB Output is correct
4 Correct 6 ms 4992 KB Output is correct
5 Correct 7 ms 4992 KB Output is correct
6 Correct 6 ms 5120 KB Output is correct
7 Correct 7 ms 4992 KB Output is correct
8 Correct 8 ms 4992 KB Output is correct
9 Correct 6 ms 5144 KB Output is correct
10 Correct 8 ms 4992 KB Output is correct
11 Correct 7 ms 4992 KB Output is correct
12 Correct 6 ms 4992 KB Output is correct
13 Correct 6 ms 5092 KB Output is correct
14 Correct 7 ms 5120 KB Output is correct
15 Correct 7 ms 4992 KB Output is correct
16 Correct 7 ms 5120 KB Output is correct
17 Correct 7 ms 5120 KB Output is correct
18 Correct 8 ms 5120 KB Output is correct
19 Correct 7 ms 5120 KB Output is correct
20 Correct 7 ms 4992 KB Output is correct
21 Correct 7 ms 5120 KB Output is correct
22 Correct 13 ms 10112 KB Output is correct
23 Correct 13 ms 9472 KB Output is correct
24 Correct 16 ms 10880 KB Output is correct
25 Correct 13 ms 8576 KB Output is correct
26 Correct 12 ms 7808 KB Output is correct
27 Correct 3 ms 5120 KB Output is correct
28 Correct 9 ms 6656 KB Output is correct
29 Correct 11 ms 7680 KB Output is correct
30 Correct 11 ms 7936 KB Output is correct
31 Correct 12 ms 8832 KB Output is correct
32 Correct 13 ms 8832 KB Output is correct
33 Correct 14 ms 10340 KB Output is correct
34 Correct 14 ms 9472 KB Output is correct
35 Correct 17 ms 11008 KB Output is correct
36 Correct 16 ms 11520 KB Output is correct
37 Correct 12 ms 8960 KB Output is correct
38 Correct 11 ms 7424 KB Output is correct
39 Correct 244 ms 10744 KB Output is correct
40 Correct 232 ms 10716 KB Output is correct
41 Correct 260 ms 10744 KB Output is correct
42 Correct 215 ms 10960 KB Output is correct
43 Correct 123 ms 11000 KB Output is correct
44 Correct 99 ms 10744 KB Output is correct
45 Correct 251 ms 12712 KB Output is correct
46 Correct 111 ms 16120 KB Output is correct
47 Correct 312 ms 19432 KB Output is correct
48 Correct 536 ms 27640 KB Output is correct
49 Correct 590 ms 27000 KB Output is correct
50 Correct 291 ms 19356 KB Output is correct
51 Correct 307 ms 19320 KB Output is correct
52 Correct 318 ms 19448 KB Output is correct
53 Correct 429 ms 18300 KB Output is correct
54 Correct 411 ms 19064 KB Output is correct
55 Correct 13 ms 5856 KB Output is correct
56 Correct 19 ms 5760 KB Output is correct
57 Correct 100 ms 12280 KB Output is correct
58 Correct 51 ms 12140 KB Output is correct
59 Correct 137 ms 16988 KB Output is correct
60 Correct 890 ms 31960 KB Output is correct
61 Correct 280 ms 19704 KB Output is correct
62 Correct 344 ms 19448 KB Output is correct
63 Correct 392 ms 19528 KB Output is correct
64 Correct 879 ms 22012 KB Output is correct
65 Correct 411 ms 20472 KB Output is correct
66 Correct 845 ms 33400 KB Output is correct
67 Correct 185 ms 20196 KB Output is correct
68 Correct 426 ms 25464 KB Output is correct
69 Correct 436 ms 25996 KB Output is correct
70 Correct 399 ms 24808 KB Output is correct