Submission #1026072

# Submission time Handle Problem Language Result Execution time Memory
1026072 2024-07-17T13:59:16 Z vanea Race (IOI11_race) C++14
21 / 100
3000 ms 19024 KB
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

const int mxN = 2e5+10;
const int mxK = 1e6+10;
const int INF = 1e9+10;
int ans = INF, k, mx;
int d[mxK];

vector<array<int, 2>> adj[mxN];

bool vis[mxN];
int sz[mxN];

void get_sz(int node, int p) {
    sz[node] = 1;
    for(auto [it, w] : adj[node]) {
        if(it == p || vis[it]) continue;
        get_sz(it, node);
        sz[node] += sz[it];
    }
}

int get_c(int node, int p, int n) {
    for(auto [it, w] : adj[node]) {
        if(vis[it] || it == p) continue;
        if(sz[it] * 2 > n) return get_c(it, node, p);
    }
    return node;
}

void get_min(int node, int p, bool filling, int dist, int s) {
    if(s > k) return ;
    mx = max(mx, s);
    if(filling) {
        d[s] = min(d[s], dist);
    }
    else {
        ans = min(ans, dist+d[k-s]);
    }
    for(auto [it, w] : adj[node]) {
        if(it == p || vis[it]) continue;
        get_min(it, node, filling, dist+1, s+w);
    }
}

void build(int node) {
    get_sz(node, -1);
    int c = get_c(node, -1, sz[node]);
    vis[c] = true;
    mx = 0;
    d[0] = 0;
    for(auto [it, w] : adj[c]) {
        if(vis[it]) continue;
        get_min(it, c, 0, 1, w);
        get_min(it, c, 1, 1, w);
    }
    fill(d, d+mx+1, INF);
    for(auto [it, w] : adj[c]) {
        if(vis[it]) continue;
        build(it);
    }
}

int best_path(int n, int K, int h[][2], int l[]) {
    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]});
    }
    d[0] = 0;
    memset(d, 0x3F, sizeof d);
    k = K;
    build(0);
    return (ans == INF ? -1 : ans);
}
/*
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout << best_path(4, 3, {{0, 1}, {1, 2}, {1, 3}},
                      {1, 2, 4});
}*/

Compilation message

race.cpp: In function 'void get_sz(int, int)':
race.cpp:18:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   18 |     for(auto [it, w] : adj[node]) {
      |              ^
race.cpp: In function 'int get_c(int, int, int)':
race.cpp:26:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   26 |     for(auto [it, w] : adj[node]) {
      |              ^
race.cpp: In function 'void get_min(int, int, bool, int, int)':
race.cpp:42:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   42 |     for(auto [it, w] : adj[node]) {
      |              ^
race.cpp: In function 'void build(int)':
race.cpp:54:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   54 |     for(auto [it, w] : adj[c]) {
      |              ^
race.cpp:60:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   60 |     for(auto [it, w] : adj[c]) {
      |              ^
# Verdict Execution time Memory Grader output
1 Correct 5 ms 9048 KB Output is correct
2 Correct 3 ms 9052 KB Output is correct
3 Correct 3 ms 9052 KB Output is correct
4 Correct 4 ms 9052 KB Output is correct
5 Correct 4 ms 8892 KB Output is correct
6 Correct 5 ms 9052 KB Output is correct
7 Correct 3 ms 9052 KB Output is correct
8 Correct 3 ms 9052 KB Output is correct
9 Correct 4 ms 9052 KB Output is correct
10 Correct 3 ms 9052 KB Output is correct
11 Correct 3 ms 9076 KB Output is correct
12 Correct 3 ms 9052 KB Output is correct
13 Correct 3 ms 9052 KB Output is correct
14 Correct 3 ms 9052 KB Output is correct
15 Correct 3 ms 9052 KB Output is correct
16 Correct 3 ms 9052 KB Output is correct
17 Correct 3 ms 9052 KB Output is correct
18 Correct 3 ms 9052 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 9048 KB Output is correct
2 Correct 3 ms 9052 KB Output is correct
3 Correct 3 ms 9052 KB Output is correct
4 Correct 4 ms 9052 KB Output is correct
5 Correct 4 ms 8892 KB Output is correct
6 Correct 5 ms 9052 KB Output is correct
7 Correct 3 ms 9052 KB Output is correct
8 Correct 3 ms 9052 KB Output is correct
9 Correct 4 ms 9052 KB Output is correct
10 Correct 3 ms 9052 KB Output is correct
11 Correct 3 ms 9076 KB Output is correct
12 Correct 3 ms 9052 KB Output is correct
13 Correct 3 ms 9052 KB Output is correct
14 Correct 3 ms 9052 KB Output is correct
15 Correct 3 ms 9052 KB Output is correct
16 Correct 3 ms 9052 KB Output is correct
17 Correct 3 ms 9052 KB Output is correct
18 Correct 3 ms 9052 KB Output is correct
19 Correct 4 ms 9052 KB Output is correct
20 Correct 3 ms 8988 KB Output is correct
21 Correct 4 ms 9036 KB Output is correct
22 Correct 122 ms 9052 KB Output is correct
23 Correct 99 ms 9112 KB Output is correct
24 Correct 103 ms 9108 KB Output is correct
25 Correct 19 ms 9052 KB Output is correct
26 Correct 42 ms 9052 KB Output is correct
27 Correct 4 ms 9052 KB Output is correct
28 Correct 17 ms 9128 KB Output is correct
29 Correct 20 ms 9136 KB Output is correct
30 Correct 17 ms 9120 KB Output is correct
31 Correct 19 ms 9052 KB Output is correct
32 Correct 20 ms 9128 KB Output is correct
33 Correct 27 ms 8996 KB Output is correct
34 Correct 52 ms 9048 KB Output is correct
35 Correct 93 ms 9052 KB Output is correct
36 Correct 71 ms 9048 KB Output is correct
37 Correct 22 ms 9048 KB Output is correct
38 Correct 13 ms 9048 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 9048 KB Output is correct
2 Correct 3 ms 9052 KB Output is correct
3 Correct 3 ms 9052 KB Output is correct
4 Correct 4 ms 9052 KB Output is correct
5 Correct 4 ms 8892 KB Output is correct
6 Correct 5 ms 9052 KB Output is correct
7 Correct 3 ms 9052 KB Output is correct
8 Correct 3 ms 9052 KB Output is correct
9 Correct 4 ms 9052 KB Output is correct
10 Correct 3 ms 9052 KB Output is correct
11 Correct 3 ms 9076 KB Output is correct
12 Correct 3 ms 9052 KB Output is correct
13 Correct 3 ms 9052 KB Output is correct
14 Correct 3 ms 9052 KB Output is correct
15 Correct 3 ms 9052 KB Output is correct
16 Correct 3 ms 9052 KB Output is correct
17 Correct 3 ms 9052 KB Output is correct
18 Correct 3 ms 9052 KB Output is correct
19 Correct 502 ms 14420 KB Output is correct
20 Correct 508 ms 15444 KB Output is correct
21 Correct 861 ms 15196 KB Output is correct
22 Correct 86 ms 15624 KB Output is correct
23 Correct 45 ms 15880 KB Output is correct
24 Correct 34 ms 15696 KB Output is correct
25 Execution timed out 3050 ms 19024 KB Time limit exceeded
26 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 9048 KB Output is correct
2 Correct 3 ms 9052 KB Output is correct
3 Correct 3 ms 9052 KB Output is correct
4 Correct 4 ms 9052 KB Output is correct
5 Correct 4 ms 8892 KB Output is correct
6 Correct 5 ms 9052 KB Output is correct
7 Correct 3 ms 9052 KB Output is correct
8 Correct 3 ms 9052 KB Output is correct
9 Correct 4 ms 9052 KB Output is correct
10 Correct 3 ms 9052 KB Output is correct
11 Correct 3 ms 9076 KB Output is correct
12 Correct 3 ms 9052 KB Output is correct
13 Correct 3 ms 9052 KB Output is correct
14 Correct 3 ms 9052 KB Output is correct
15 Correct 3 ms 9052 KB Output is correct
16 Correct 3 ms 9052 KB Output is correct
17 Correct 3 ms 9052 KB Output is correct
18 Correct 3 ms 9052 KB Output is correct
19 Correct 4 ms 9052 KB Output is correct
20 Correct 3 ms 8988 KB Output is correct
21 Correct 4 ms 9036 KB Output is correct
22 Correct 122 ms 9052 KB Output is correct
23 Correct 99 ms 9112 KB Output is correct
24 Correct 103 ms 9108 KB Output is correct
25 Correct 19 ms 9052 KB Output is correct
26 Correct 42 ms 9052 KB Output is correct
27 Correct 4 ms 9052 KB Output is correct
28 Correct 17 ms 9128 KB Output is correct
29 Correct 20 ms 9136 KB Output is correct
30 Correct 17 ms 9120 KB Output is correct
31 Correct 19 ms 9052 KB Output is correct
32 Correct 20 ms 9128 KB Output is correct
33 Correct 27 ms 8996 KB Output is correct
34 Correct 52 ms 9048 KB Output is correct
35 Correct 93 ms 9052 KB Output is correct
36 Correct 71 ms 9048 KB Output is correct
37 Correct 22 ms 9048 KB Output is correct
38 Correct 13 ms 9048 KB Output is correct
39 Correct 502 ms 14420 KB Output is correct
40 Correct 508 ms 15444 KB Output is correct
41 Correct 861 ms 15196 KB Output is correct
42 Correct 86 ms 15624 KB Output is correct
43 Correct 45 ms 15880 KB Output is correct
44 Correct 34 ms 15696 KB Output is correct
45 Execution timed out 3050 ms 19024 KB Time limit exceeded
46 Halted 0 ms 0 KB -