Submission #1079019

# Submission time Handle Problem Language Result Execution time Memory
1079019 2024-08-28T09:28:49 Z coolboy19521 Race (IOI11_race) C++17
21 / 100
1053 ms 262144 KB
#include "race.h"
#include "bits/stdc++.h"
#include "ext/pb_ds/assoc_container.hpp"
#define ll long long
#define int ll

using namespace std;
using namespace __gnu_pbds;

const int sz = 2e5 + 10;

gp_hash_table<int,int> mc[sz], ban;
vector<pair<int,int>> aj[sz];
int ts[sz], k, r;

int uk(int v, int p = -1) {
    ts[v] = 1;
    for (auto& [u, _] : aj[v]) if (u != p)
        ts[v] += uk(u, v);
    return ts[v];
}

int fC(int v, int p = -1) {
    for (auto& [u, _] : aj[v])
        if (u != p && !ban[u])
        if (ts[u] > ts[v] / 2) {
            ts[v] -= ts[u];
            ts[u] += ts[v];
            return fC(u, v);
        }
    return v;
}

void marj(int v, int u) {
    for (auto& [tr, mn] : mc[u])
        if (mc[v].find(tr) != end(mc[v]))
            mc[v][tr] = min(mc[v][tr], mn);
        else mc[v][tr] = mn;
    mc[u].clear();
}

void dfs(int v, int p, int l, int d = 1) {
    mc[v][l] = d;
    for (auto& [u, w] : aj[v])
        if (u != p && !ban[u]) {
            dfs(u, v, l + w, d + 1);
            if (mc[v].size() < mc[u].size())
                mc[v].swap(mc[u]);
            marj(v, u);
        }
}

void cD(int v) {
    v = fC(v);
    mc[v].clear();
    for (auto& [u, w] : aj[v]) if (!ban[u]) {
        dfs(u, v, w);
        if (mc[v].size() < mc[u].size())
            mc[v].swap(mc[u]);
        for (auto& [tr, mn] : mc[u])
            if (mc[v].find(k - tr) != end(mc[v]))
                r = min(r, mn + mc[v][k - tr]);
        marj(v, u);
    }
    if (mc[v].find(k) != end(mc[v]))
        r = min(r, mc[v][k]);
    ban[v] = 1;
    for (auto& [u, _] : aj[v])
        if (!ban[u]) cD(u);
}

signed best_path(signed N, signed K, signed H[][2], signed L[]) {
    if (1 == N) {
        if (0 == K) return 0;
        else return -1;
    }
    for (int i = 0; i < N - 1; i ++) {
        int a = H[i][0], b = H[i][1];
        aj[a].emplace_back(b, L[i]);
        aj[b].emplace_back(a, L[i]);
    }
    r = N, k = K;
    uk(0);
    cD(0);
    return r < N ? r : -1;
}
# Verdict Execution time Memory Grader output
1 Correct 45 ms 66396 KB Output is correct
2 Correct 36 ms 66136 KB Output is correct
3 Correct 54 ms 67152 KB Output is correct
4 Correct 37 ms 66140 KB Output is correct
5 Correct 40 ms 66136 KB Output is correct
6 Correct 44 ms 66132 KB Output is correct
7 Correct 38 ms 66000 KB Output is correct
8 Correct 37 ms 66120 KB Output is correct
9 Correct 42 ms 66028 KB Output is correct
10 Correct 35 ms 66132 KB Output is correct
11 Correct 41 ms 66132 KB Output is correct
12 Correct 41 ms 66040 KB Output is correct
13 Correct 35 ms 66140 KB Output is correct
14 Correct 39 ms 66124 KB Output is correct
15 Correct 36 ms 66128 KB Output is correct
16 Correct 37 ms 66140 KB Output is correct
17 Correct 35 ms 66132 KB Output is correct
18 Correct 39 ms 66140 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 45 ms 66396 KB Output is correct
2 Correct 36 ms 66136 KB Output is correct
3 Correct 54 ms 67152 KB Output is correct
4 Correct 37 ms 66140 KB Output is correct
5 Correct 40 ms 66136 KB Output is correct
6 Correct 44 ms 66132 KB Output is correct
7 Correct 38 ms 66000 KB Output is correct
8 Correct 37 ms 66120 KB Output is correct
9 Correct 42 ms 66028 KB Output is correct
10 Correct 35 ms 66132 KB Output is correct
11 Correct 41 ms 66132 KB Output is correct
12 Correct 41 ms 66040 KB Output is correct
13 Correct 35 ms 66140 KB Output is correct
14 Correct 39 ms 66124 KB Output is correct
15 Correct 36 ms 66128 KB Output is correct
16 Correct 37 ms 66140 KB Output is correct
17 Correct 35 ms 66132 KB Output is correct
18 Correct 39 ms 66140 KB Output is correct
19 Correct 37 ms 66140 KB Output is correct
20 Correct 35 ms 66140 KB Output is correct
21 Correct 40 ms 66396 KB Output is correct
22 Correct 38 ms 66644 KB Output is correct
23 Correct 41 ms 66664 KB Output is correct
24 Correct 40 ms 66576 KB Output is correct
25 Correct 38 ms 66388 KB Output is correct
26 Correct 39 ms 66384 KB Output is correct
27 Correct 37 ms 66384 KB Output is correct
28 Correct 38 ms 66428 KB Output is correct
29 Correct 38 ms 66444 KB Output is correct
30 Correct 40 ms 66412 KB Output is correct
31 Correct 38 ms 66652 KB Output is correct
32 Correct 35 ms 66652 KB Output is correct
33 Correct 38 ms 66640 KB Output is correct
34 Correct 38 ms 66588 KB Output is correct
35 Correct 34 ms 66644 KB Output is correct
36 Correct 38 ms 66644 KB Output is correct
37 Correct 55 ms 66728 KB Output is correct
38 Correct 47 ms 66580 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 45 ms 66396 KB Output is correct
2 Correct 36 ms 66136 KB Output is correct
3 Correct 54 ms 67152 KB Output is correct
4 Correct 37 ms 66140 KB Output is correct
5 Correct 40 ms 66136 KB Output is correct
6 Correct 44 ms 66132 KB Output is correct
7 Correct 38 ms 66000 KB Output is correct
8 Correct 37 ms 66120 KB Output is correct
9 Correct 42 ms 66028 KB Output is correct
10 Correct 35 ms 66132 KB Output is correct
11 Correct 41 ms 66132 KB Output is correct
12 Correct 41 ms 66040 KB Output is correct
13 Correct 35 ms 66140 KB Output is correct
14 Correct 39 ms 66124 KB Output is correct
15 Correct 36 ms 66128 KB Output is correct
16 Correct 37 ms 66140 KB Output is correct
17 Correct 35 ms 66132 KB Output is correct
18 Correct 39 ms 66140 KB Output is correct
19 Correct 393 ms 100708 KB Output is correct
20 Correct 371 ms 100592 KB Output is correct
21 Correct 377 ms 99312 KB Output is correct
22 Correct 381 ms 98036 KB Output is correct
23 Correct 617 ms 122748 KB Output is correct
24 Correct 280 ms 98800 KB Output is correct
25 Correct 335 ms 93616 KB Output is correct
26 Correct 191 ms 88260 KB Output is correct
27 Correct 390 ms 145224 KB Output is correct
28 Runtime error 1053 ms 262144 KB Execution killed with signal 9
29 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 45 ms 66396 KB Output is correct
2 Correct 36 ms 66136 KB Output is correct
3 Correct 54 ms 67152 KB Output is correct
4 Correct 37 ms 66140 KB Output is correct
5 Correct 40 ms 66136 KB Output is correct
6 Correct 44 ms 66132 KB Output is correct
7 Correct 38 ms 66000 KB Output is correct
8 Correct 37 ms 66120 KB Output is correct
9 Correct 42 ms 66028 KB Output is correct
10 Correct 35 ms 66132 KB Output is correct
11 Correct 41 ms 66132 KB Output is correct
12 Correct 41 ms 66040 KB Output is correct
13 Correct 35 ms 66140 KB Output is correct
14 Correct 39 ms 66124 KB Output is correct
15 Correct 36 ms 66128 KB Output is correct
16 Correct 37 ms 66140 KB Output is correct
17 Correct 35 ms 66132 KB Output is correct
18 Correct 39 ms 66140 KB Output is correct
19 Correct 37 ms 66140 KB Output is correct
20 Correct 35 ms 66140 KB Output is correct
21 Correct 40 ms 66396 KB Output is correct
22 Correct 38 ms 66644 KB Output is correct
23 Correct 41 ms 66664 KB Output is correct
24 Correct 40 ms 66576 KB Output is correct
25 Correct 38 ms 66388 KB Output is correct
26 Correct 39 ms 66384 KB Output is correct
27 Correct 37 ms 66384 KB Output is correct
28 Correct 38 ms 66428 KB Output is correct
29 Correct 38 ms 66444 KB Output is correct
30 Correct 40 ms 66412 KB Output is correct
31 Correct 38 ms 66652 KB Output is correct
32 Correct 35 ms 66652 KB Output is correct
33 Correct 38 ms 66640 KB Output is correct
34 Correct 38 ms 66588 KB Output is correct
35 Correct 34 ms 66644 KB Output is correct
36 Correct 38 ms 66644 KB Output is correct
37 Correct 55 ms 66728 KB Output is correct
38 Correct 47 ms 66580 KB Output is correct
39 Correct 393 ms 100708 KB Output is correct
40 Correct 371 ms 100592 KB Output is correct
41 Correct 377 ms 99312 KB Output is correct
42 Correct 381 ms 98036 KB Output is correct
43 Correct 617 ms 122748 KB Output is correct
44 Correct 280 ms 98800 KB Output is correct
45 Correct 335 ms 93616 KB Output is correct
46 Correct 191 ms 88260 KB Output is correct
47 Correct 390 ms 145224 KB Output is correct
48 Runtime error 1053 ms 262144 KB Execution killed with signal 9
49 Halted 0 ms 0 KB -