Submission #330982

# Submission time Handle Problem Language Result Execution time Memory
330982 2020-11-27T02:42:00 Z quindecim Race (IOI11_race) C++14
100 / 100
531 ms 33260 KB
#include "race.h"
#pragma GCC optimize ("Ofast")
#pragma GCC target ("avx2")
#include <bits/stdc++.h>
using namespace std;
using ull = long long;
const int INF = 0x3f3f3f3f;
const int MX = 200005;

int ans = INF, k, s[MX], used[300005], c;
vector<pair<int, int>> adj[MX], t;
vector<int> val(1000005, INF);
bitset<MX> r;

int dfs(int u, int p) {
    s[u] = 1;
    for(auto &v : adj[u])
        if(v.first!=p&&!r[v.first])
            s[u] += dfs(v.first, u);
    return s[u];
}

void dfs2(int u, int p, int l, int c) {
    if(k-l<0) return;
    if(val[k-l]!=INF) ans = min(ans, val[k-l]+c);
    t.push_back({l, c});
    for(auto &v : adj[u])
        if(v.first!=p&&!r[v.first])
            dfs2(v.first, u, l+v.second, c+1);
}

int get_centroid(int u, int p, int ms) {
    for(auto &v : adj[u])
        if(v.first!=p&&!r[v.first]&&s[v.first]*2>ms)
            return get_centroid(v.first, u, ms);
    return u;
}

void centroid(int u = 1) {
    int C = get_centroid(u, u, dfs(u, u));
    r[C] = 1;
    c = 0;
    for(auto &x : adj[C]) {
        if(!r[x.first]) {
            t.clear();
            dfs2(x.first, C, x.second, 1);
            for(auto &i : t) {
                if(i.first<=k) {
                    val[i.first] = min(val[i.first], i.second);
                    used[++c] = i.first;
                }
            }
        }
    }
    ans = min(ans, val[k]);
    for(; c; c--)
        val[used[c]] = INF;
    for(auto v : adj[C])
        if(!r[v.first])
            centroid(v.first);
}

int best_path(int N, int K, int H[][2], int L[]) {
    k = K;
    for(int i = 0; i < N-1; ++i) {
        adj[H[i][0]].push_back({H[i][1], L[i]});
        adj[H[i][1]].push_back({H[i][0], L[i]});
    }
    centroid();
    if(ans==INF) ans = -1;
    return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 6 ms 8940 KB Output is correct
2 Correct 6 ms 8940 KB Output is correct
3 Correct 6 ms 8940 KB Output is correct
4 Correct 6 ms 8940 KB Output is correct
5 Correct 6 ms 8940 KB Output is correct
6 Correct 6 ms 8940 KB Output is correct
7 Correct 6 ms 8940 KB Output is correct
8 Correct 6 ms 8940 KB Output is correct
9 Correct 6 ms 8940 KB Output is correct
10 Correct 6 ms 8940 KB Output is correct
11 Correct 6 ms 8940 KB Output is correct
12 Correct 6 ms 8940 KB Output is correct
13 Correct 6 ms 8940 KB Output is correct
14 Correct 6 ms 8940 KB Output is correct
15 Correct 6 ms 8940 KB Output is correct
16 Correct 6 ms 8940 KB Output is correct
17 Correct 6 ms 8940 KB Output is correct
18 Correct 6 ms 8940 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 8940 KB Output is correct
2 Correct 6 ms 8940 KB Output is correct
3 Correct 6 ms 8940 KB Output is correct
4 Correct 6 ms 8940 KB Output is correct
5 Correct 6 ms 8940 KB Output is correct
6 Correct 6 ms 8940 KB Output is correct
7 Correct 6 ms 8940 KB Output is correct
8 Correct 6 ms 8940 KB Output is correct
9 Correct 6 ms 8940 KB Output is correct
10 Correct 6 ms 8940 KB Output is correct
11 Correct 6 ms 8940 KB Output is correct
12 Correct 6 ms 8940 KB Output is correct
13 Correct 6 ms 8940 KB Output is correct
14 Correct 6 ms 8940 KB Output is correct
15 Correct 6 ms 8940 KB Output is correct
16 Correct 6 ms 8940 KB Output is correct
17 Correct 6 ms 8940 KB Output is correct
18 Correct 6 ms 8940 KB Output is correct
19 Correct 6 ms 8940 KB Output is correct
20 Correct 6 ms 8940 KB Output is correct
21 Correct 7 ms 9068 KB Output is correct
22 Correct 7 ms 9068 KB Output is correct
23 Correct 7 ms 9068 KB Output is correct
24 Correct 7 ms 9068 KB Output is correct
25 Correct 7 ms 9068 KB Output is correct
26 Correct 7 ms 9068 KB Output is correct
27 Correct 7 ms 9068 KB Output is correct
28 Correct 7 ms 9068 KB Output is correct
29 Correct 7 ms 9068 KB Output is correct
30 Correct 7 ms 9068 KB Output is correct
31 Correct 7 ms 9068 KB Output is correct
32 Correct 7 ms 9068 KB Output is correct
33 Correct 7 ms 9068 KB Output is correct
34 Correct 7 ms 9068 KB Output is correct
35 Correct 7 ms 9068 KB Output is correct
36 Correct 7 ms 9068 KB Output is correct
37 Correct 7 ms 9068 KB Output is correct
38 Correct 7 ms 9068 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 8940 KB Output is correct
2 Correct 6 ms 8940 KB Output is correct
3 Correct 6 ms 8940 KB Output is correct
4 Correct 6 ms 8940 KB Output is correct
5 Correct 6 ms 8940 KB Output is correct
6 Correct 6 ms 8940 KB Output is correct
7 Correct 6 ms 8940 KB Output is correct
8 Correct 6 ms 8940 KB Output is correct
9 Correct 6 ms 8940 KB Output is correct
10 Correct 6 ms 8940 KB Output is correct
11 Correct 6 ms 8940 KB Output is correct
12 Correct 6 ms 8940 KB Output is correct
13 Correct 6 ms 8940 KB Output is correct
14 Correct 6 ms 8940 KB Output is correct
15 Correct 6 ms 8940 KB Output is correct
16 Correct 6 ms 8940 KB Output is correct
17 Correct 6 ms 8940 KB Output is correct
18 Correct 6 ms 8940 KB Output is correct
19 Correct 153 ms 15736 KB Output is correct
20 Correct 165 ms 15896 KB Output is correct
21 Correct 152 ms 15980 KB Output is correct
22 Correct 158 ms 16488 KB Output is correct
23 Correct 90 ms 15852 KB Output is correct
24 Correct 68 ms 15852 KB Output is correct
25 Correct 138 ms 20716 KB Output is correct
26 Correct 110 ms 22252 KB Output is correct
27 Correct 215 ms 22636 KB Output is correct
28 Correct 322 ms 33260 KB Output is correct
29 Correct 306 ms 29036 KB Output is correct
30 Correct 218 ms 22636 KB Output is correct
31 Correct 213 ms 22636 KB Output is correct
32 Correct 265 ms 22764 KB Output is correct
33 Correct 257 ms 21484 KB Output is correct
34 Correct 224 ms 22252 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 8940 KB Output is correct
2 Correct 6 ms 8940 KB Output is correct
3 Correct 6 ms 8940 KB Output is correct
4 Correct 6 ms 8940 KB Output is correct
5 Correct 6 ms 8940 KB Output is correct
6 Correct 6 ms 8940 KB Output is correct
7 Correct 6 ms 8940 KB Output is correct
8 Correct 6 ms 8940 KB Output is correct
9 Correct 6 ms 8940 KB Output is correct
10 Correct 6 ms 8940 KB Output is correct
11 Correct 6 ms 8940 KB Output is correct
12 Correct 6 ms 8940 KB Output is correct
13 Correct 6 ms 8940 KB Output is correct
14 Correct 6 ms 8940 KB Output is correct
15 Correct 6 ms 8940 KB Output is correct
16 Correct 6 ms 8940 KB Output is correct
17 Correct 6 ms 8940 KB Output is correct
18 Correct 6 ms 8940 KB Output is correct
19 Correct 6 ms 8940 KB Output is correct
20 Correct 6 ms 8940 KB Output is correct
21 Correct 7 ms 9068 KB Output is correct
22 Correct 7 ms 9068 KB Output is correct
23 Correct 7 ms 9068 KB Output is correct
24 Correct 7 ms 9068 KB Output is correct
25 Correct 7 ms 9068 KB Output is correct
26 Correct 7 ms 9068 KB Output is correct
27 Correct 7 ms 9068 KB Output is correct
28 Correct 7 ms 9068 KB Output is correct
29 Correct 7 ms 9068 KB Output is correct
30 Correct 7 ms 9068 KB Output is correct
31 Correct 7 ms 9068 KB Output is correct
32 Correct 7 ms 9068 KB Output is correct
33 Correct 7 ms 9068 KB Output is correct
34 Correct 7 ms 9068 KB Output is correct
35 Correct 7 ms 9068 KB Output is correct
36 Correct 7 ms 9068 KB Output is correct
37 Correct 7 ms 9068 KB Output is correct
38 Correct 7 ms 9068 KB Output is correct
39 Correct 153 ms 15736 KB Output is correct
40 Correct 165 ms 15896 KB Output is correct
41 Correct 152 ms 15980 KB Output is correct
42 Correct 158 ms 16488 KB Output is correct
43 Correct 90 ms 15852 KB Output is correct
44 Correct 68 ms 15852 KB Output is correct
45 Correct 138 ms 20716 KB Output is correct
46 Correct 110 ms 22252 KB Output is correct
47 Correct 215 ms 22636 KB Output is correct
48 Correct 322 ms 33260 KB Output is correct
49 Correct 306 ms 29036 KB Output is correct
50 Correct 218 ms 22636 KB Output is correct
51 Correct 213 ms 22636 KB Output is correct
52 Correct 265 ms 22764 KB Output is correct
53 Correct 257 ms 21484 KB Output is correct
54 Correct 224 ms 22252 KB Output is correct
55 Correct 14 ms 9708 KB Output is correct
56 Correct 16 ms 9708 KB Output is correct
57 Correct 97 ms 16744 KB Output is correct
58 Correct 46 ms 15968 KB Output is correct
59 Correct 109 ms 22252 KB Output is correct
60 Correct 452 ms 30816 KB Output is correct
61 Correct 225 ms 22892 KB Output is correct
62 Correct 241 ms 23404 KB Output is correct
63 Correct 308 ms 23532 KB Output is correct
64 Correct 531 ms 24544 KB Output is correct
65 Correct 298 ms 23532 KB Output is correct
66 Correct 448 ms 32364 KB Output is correct
67 Correct 154 ms 24028 KB Output is correct
68 Correct 302 ms 23788 KB Output is correct
69 Correct 319 ms 23916 KB Output is correct
70 Correct 282 ms 23148 KB Output is correct