Submission #100454

# Submission time Handle Problem Language Result Execution time Memory
100454 2019-03-11T11:07:28 Z alexpetrescu Race (IOI11_race) C++14
100 / 100
2958 ms 87800 KB
#include "race.h"
#include <vector>
#include <map>

#define MAXN 200000

struct myc {int x, y;};
std::map <long long, myc> val;
int timp;
std::vector < myc > g[MAXN];
int s[MAXN], k, h[MAXN];
int fiuMare[MAXN], t[MAXN];
long long u[MAXN];
int ans, cine;
bool tip;

void dfs(int x) {
    s[x] = 1;
    fiuMare[x] = x;
    for (auto &y : g[x]) {
        if (h[y.x] == 0) {
            h[y.x] = h[x] + 1;
            u[y.x] = u[x] + y.y;
            t[y.x] = x;
            dfs(y.x);
            s[x] += s[y.x];
            if (s[y.x] > s[fiuMare[x]] || fiuMare[x] == x)
                fiuMare[x] = y.x;
        }
    }
}

inline void vezi(int x) {
    if (ans == -1 || x < ans)
        ans = x;
}

inline void baga(int x) {
    myc &t = val[u[x]];
    if (t.y != timp || t.x > h[x])
        t = {h[x], timp};
}

void tot(int x) {
    if (tip)
        baga(x);
    else {
        int e = k + 2 * u[cine] - u[x];
        if (e >= 0 && val[e].y == timp)
            vezi(h[x] - 2 * h[cine] + val[e].x);
    }
    for (auto &y : g[x])
        if (t[y.x] == x)
            tot(y.x);
}

inline void solve(int x) {
    bool ok = 1;
    while (ok) {
        for (auto &y : g[x]) {
            if (t[y.x] == x && y.x != fiuMare[x]) {
                cine = x;
                tip = 0;
                tot(y.x);
                tip = 1;
                tot(y.x);
            }
        }
        baga(x);
        int e = u[x] + k;
        if (e >= 0 && val[e].y == timp)
            vezi(val[e].x - h[x]);
        if (t[x] != -1 && fiuMare[t[x]] == x)
            x = t[x];
        else
            ok = 0;
    }
}

int best_path(int N, int K, int H[][2], int L[]) {
    for (int i = 0; i < N - 1; i++)g[H[i][0]].push_back({H[i][1], L[i]}), g[H[i][1]].push_back({H[i][0], L[i]});
    for (int i = 0; i < N; i++)
        h[i] = 0;
    int rad = 0;
    h[rad] = 1;
    u[rad] = 0;
    t[rad] = -1;
    dfs(rad);
    ans = -1;
    k = K;
    for (int i = 0; i < N; i++) {
        if (fiuMare[i] == i) {
            timp++;
            solve(i);
        }
    }
    return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 6 ms 5120 KB Output is correct
2 Correct 6 ms 4992 KB Output is correct
3 Correct 6 ms 5120 KB Output is correct
4 Correct 6 ms 5092 KB Output is correct
5 Correct 6 ms 5120 KB Output is correct
6 Correct 7 ms 4992 KB Output is correct
7 Correct 7 ms 5120 KB Output is correct
8 Correct 6 ms 5180 KB Output is correct
9 Correct 8 ms 5120 KB Output is correct
10 Correct 7 ms 5120 KB Output is correct
11 Correct 6 ms 5120 KB Output is correct
12 Correct 6 ms 5120 KB Output is correct
13 Correct 6 ms 5120 KB Output is correct
14 Correct 6 ms 4992 KB Output is correct
15 Correct 6 ms 4992 KB Output is correct
16 Correct 6 ms 5120 KB Output is correct
17 Correct 6 ms 5120 KB Output is correct
18 Correct 6 ms 4992 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 5120 KB Output is correct
2 Correct 6 ms 4992 KB Output is correct
3 Correct 6 ms 5120 KB Output is correct
4 Correct 6 ms 5092 KB Output is correct
5 Correct 6 ms 5120 KB Output is correct
6 Correct 7 ms 4992 KB Output is correct
7 Correct 7 ms 5120 KB Output is correct
8 Correct 6 ms 5180 KB Output is correct
9 Correct 8 ms 5120 KB Output is correct
10 Correct 7 ms 5120 KB Output is correct
11 Correct 6 ms 5120 KB Output is correct
12 Correct 6 ms 5120 KB Output is correct
13 Correct 6 ms 5120 KB Output is correct
14 Correct 6 ms 4992 KB Output is correct
15 Correct 6 ms 4992 KB Output is correct
16 Correct 6 ms 5120 KB Output is correct
17 Correct 6 ms 5120 KB Output is correct
18 Correct 6 ms 4992 KB Output is correct
19 Correct 7 ms 5076 KB Output is correct
20 Correct 7 ms 5120 KB Output is correct
21 Correct 7 ms 5120 KB Output is correct
22 Correct 9 ms 5376 KB Output is correct
23 Correct 9 ms 5376 KB Output is correct
24 Correct 8 ms 5376 KB Output is correct
25 Correct 8 ms 5376 KB Output is correct
26 Correct 8 ms 5376 KB Output is correct
27 Correct 8 ms 5168 KB Output is correct
28 Correct 9 ms 5376 KB Output is correct
29 Correct 8 ms 5376 KB Output is correct
30 Correct 8 ms 5376 KB Output is correct
31 Correct 8 ms 5376 KB Output is correct
32 Correct 8 ms 5376 KB Output is correct
33 Correct 8 ms 5376 KB Output is correct
34 Correct 9 ms 5248 KB Output is correct
35 Correct 9 ms 5248 KB Output is correct
36 Correct 7 ms 5248 KB Output is correct
37 Correct 7 ms 5248 KB Output is correct
38 Correct 8 ms 5248 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 5120 KB Output is correct
2 Correct 6 ms 4992 KB Output is correct
3 Correct 6 ms 5120 KB Output is correct
4 Correct 6 ms 5092 KB Output is correct
5 Correct 6 ms 5120 KB Output is correct
6 Correct 7 ms 4992 KB Output is correct
7 Correct 7 ms 5120 KB Output is correct
8 Correct 6 ms 5180 KB Output is correct
9 Correct 8 ms 5120 KB Output is correct
10 Correct 7 ms 5120 KB Output is correct
11 Correct 6 ms 5120 KB Output is correct
12 Correct 6 ms 5120 KB Output is correct
13 Correct 6 ms 5120 KB Output is correct
14 Correct 6 ms 4992 KB Output is correct
15 Correct 6 ms 4992 KB Output is correct
16 Correct 6 ms 5120 KB Output is correct
17 Correct 6 ms 5120 KB Output is correct
18 Correct 6 ms 4992 KB Output is correct
19 Correct 252 ms 13220 KB Output is correct
20 Correct 270 ms 13176 KB Output is correct
21 Correct 293 ms 13148 KB Output is correct
22 Correct 315 ms 13180 KB Output is correct
23 Correct 402 ms 13536 KB Output is correct
24 Correct 253 ms 13432 KB Output is correct
25 Correct 144 ms 16648 KB Output is correct
26 Correct 62 ms 17168 KB Output is correct
27 Correct 262 ms 20572 KB Output is correct
28 Correct 383 ms 53588 KB Output is correct
29 Correct 313 ms 52688 KB Output is correct
30 Correct 245 ms 20600 KB Output is correct
31 Correct 288 ms 20572 KB Output is correct
32 Correct 443 ms 21140 KB Output is correct
33 Correct 465 ms 19456 KB Output is correct
34 Correct 1736 ms 73152 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 5120 KB Output is correct
2 Correct 6 ms 4992 KB Output is correct
3 Correct 6 ms 5120 KB Output is correct
4 Correct 6 ms 5092 KB Output is correct
5 Correct 6 ms 5120 KB Output is correct
6 Correct 7 ms 4992 KB Output is correct
7 Correct 7 ms 5120 KB Output is correct
8 Correct 6 ms 5180 KB Output is correct
9 Correct 8 ms 5120 KB Output is correct
10 Correct 7 ms 5120 KB Output is correct
11 Correct 6 ms 5120 KB Output is correct
12 Correct 6 ms 5120 KB Output is correct
13 Correct 6 ms 5120 KB Output is correct
14 Correct 6 ms 4992 KB Output is correct
15 Correct 6 ms 4992 KB Output is correct
16 Correct 6 ms 5120 KB Output is correct
17 Correct 6 ms 5120 KB Output is correct
18 Correct 6 ms 4992 KB Output is correct
19 Correct 7 ms 5076 KB Output is correct
20 Correct 7 ms 5120 KB Output is correct
21 Correct 7 ms 5120 KB Output is correct
22 Correct 9 ms 5376 KB Output is correct
23 Correct 9 ms 5376 KB Output is correct
24 Correct 8 ms 5376 KB Output is correct
25 Correct 8 ms 5376 KB Output is correct
26 Correct 8 ms 5376 KB Output is correct
27 Correct 8 ms 5168 KB Output is correct
28 Correct 9 ms 5376 KB Output is correct
29 Correct 8 ms 5376 KB Output is correct
30 Correct 8 ms 5376 KB Output is correct
31 Correct 8 ms 5376 KB Output is correct
32 Correct 8 ms 5376 KB Output is correct
33 Correct 8 ms 5376 KB Output is correct
34 Correct 9 ms 5248 KB Output is correct
35 Correct 9 ms 5248 KB Output is correct
36 Correct 7 ms 5248 KB Output is correct
37 Correct 7 ms 5248 KB Output is correct
38 Correct 8 ms 5248 KB Output is correct
39 Correct 252 ms 13220 KB Output is correct
40 Correct 270 ms 13176 KB Output is correct
41 Correct 293 ms 13148 KB Output is correct
42 Correct 315 ms 13180 KB Output is correct
43 Correct 402 ms 13536 KB Output is correct
44 Correct 253 ms 13432 KB Output is correct
45 Correct 144 ms 16648 KB Output is correct
46 Correct 62 ms 17168 KB Output is correct
47 Correct 262 ms 20572 KB Output is correct
48 Correct 383 ms 53588 KB Output is correct
49 Correct 313 ms 52688 KB Output is correct
50 Correct 245 ms 20600 KB Output is correct
51 Correct 288 ms 20572 KB Output is correct
52 Correct 443 ms 21140 KB Output is correct
53 Correct 465 ms 19456 KB Output is correct
54 Correct 1736 ms 73152 KB Output is correct
55 Correct 35 ms 6756 KB Output is correct
56 Correct 17 ms 5888 KB Output is correct
57 Correct 107 ms 13176 KB Output is correct
58 Correct 57 ms 13292 KB Output is correct
59 Correct 142 ms 29532 KB Output is correct
60 Correct 375 ms 55260 KB Output is correct
61 Correct 376 ms 24944 KB Output is correct
62 Correct 276 ms 23256 KB Output is correct
63 Correct 412 ms 23288 KB Output is correct
64 Correct 2550 ms 51064 KB Output is correct
65 Correct 2958 ms 87800 KB Output is correct
66 Correct 355 ms 53752 KB Output is correct
67 Correct 282 ms 23592 KB Output is correct
68 Correct 1299 ms 59248 KB Output is correct
69 Correct 1393 ms 60564 KB Output is correct
70 Correct 1406 ms 57720 KB Output is correct