Submission #886117

# Submission time Handle Problem Language Result Execution time Memory
886117 2023-12-11T13:25:45 Z VMaksimoski008 Race (IOI11_race) C++14
100 / 100
369 ms 83084 KB
#include <bits/stdc++.h>
#include "race.h"
 
#define sz(x) (int)x.size()
using namespace std;
using pii = pair<int, int>;
 
int ans = 1e9, k;
vector<vector<pii> > graph;
vector<int> dist, edges;
vector<map<int, int> > sets;

void precomp(int u, int p, int e, int d) {
    edges[u] = e;
    dist[u] = d;

    for(auto &[v, w] : graph[u]) {
        if(v == p) continue;
        precomp(v, u, e + 1, d + w);
    }
}

void dfs(int u, int p) {
    sets[u][dist[u]] = edges[u];
    for(auto &[v, w] : graph[u]) {
        if(v == p) continue;
        dfs(v, u);

        if(sz(sets[u]) < sz(sets[v])) swap(sets[u], sets[v]);
        for(auto &x : sets[v])
            if(sets[u].count(k + 2 * dist[u] - x.first))
                ans = min(ans, x.second + sets[u][k+2*dist[u]-x.first] - 2 * edges[u]);
        
        for(auto &x : sets[v]) {
            if(sets[u].count(x.first)) sets[u][x.first] = min(sets[u][x.first], x.second);
            else sets[u][x.first] = x.second;
        }
    }
}
 
int best_path(int N, int K, int H[][2], int L[]) {
    k = K;
    graph.resize(N);
    dist.resize(N);
    edges.resize(N);
    sets.resize(N);
    for(int i=0; i<N-1; i++) {
        graph[H[i][0]].push_back({ H[i][1], L[i] });
        graph[H[i][1]].push_back({ H[i][0], L[i] });
    }

    precomp(0, 0, 0, 0);
    dfs(0, 0);
 
    return (ans == 1e9 ? -1 : ans);
}

Compilation message

race.cpp: In function 'void precomp(int, int, int, int)':
race.cpp:17:15: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   17 |     for(auto &[v, w] : graph[u]) {
      |               ^
race.cpp: In function 'void dfs(int, int)':
race.cpp:25:15: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   25 |     for(auto &[v, w] : graph[u]) {
      |               ^
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 2392 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 2392 KB Output is correct
16 Correct 1 ms 2392 KB Output is correct
17 Correct 1 ms 2392 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 2392 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 2392 KB Output is correct
16 Correct 1 ms 2392 KB Output is correct
17 Correct 1 ms 2392 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
19 Correct 1 ms 2392 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
21 Correct 1 ms 2648 KB Output is correct
22 Correct 3 ms 2652 KB Output is correct
23 Correct 1 ms 2652 KB Output is correct
24 Correct 2 ms 2652 KB Output is correct
25 Correct 1 ms 2648 KB Output is correct
26 Correct 1 ms 2652 KB Output is correct
27 Correct 1 ms 2652 KB Output is correct
28 Correct 1 ms 2652 KB Output is correct
29 Correct 2 ms 2652 KB Output is correct
30 Correct 2 ms 2652 KB Output is correct
31 Correct 1 ms 2652 KB Output is correct
32 Correct 1 ms 2652 KB Output is correct
33 Correct 2 ms 2652 KB Output is correct
34 Correct 2 ms 2652 KB Output is correct
35 Correct 1 ms 2652 KB Output is correct
36 Correct 1 ms 2652 KB Output is correct
37 Correct 1 ms 2652 KB Output is correct
38 Correct 1 ms 2652 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 2392 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 2392 KB Output is correct
16 Correct 1 ms 2392 KB Output is correct
17 Correct 1 ms 2392 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
19 Correct 113 ms 27892 KB Output is correct
20 Correct 97 ms 27724 KB Output is correct
21 Correct 98 ms 27484 KB Output is correct
22 Correct 104 ms 27308 KB Output is correct
23 Correct 118 ms 36792 KB Output is correct
24 Correct 100 ms 29776 KB Output is correct
25 Correct 84 ms 28948 KB Output is correct
26 Correct 50 ms 35920 KB Output is correct
27 Correct 146 ms 41988 KB Output is correct
28 Correct 209 ms 76536 KB Output is correct
29 Correct 216 ms 74832 KB Output is correct
30 Correct 150 ms 42048 KB Output is correct
31 Correct 143 ms 42080 KB Output is correct
32 Correct 206 ms 41976 KB Output is correct
33 Correct 183 ms 45652 KB Output is correct
34 Correct 272 ms 69456 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 2392 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 2392 KB Output is correct
16 Correct 1 ms 2392 KB Output is correct
17 Correct 1 ms 2392 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
19 Correct 1 ms 2392 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
21 Correct 1 ms 2648 KB Output is correct
22 Correct 3 ms 2652 KB Output is correct
23 Correct 1 ms 2652 KB Output is correct
24 Correct 2 ms 2652 KB Output is correct
25 Correct 1 ms 2648 KB Output is correct
26 Correct 1 ms 2652 KB Output is correct
27 Correct 1 ms 2652 KB Output is correct
28 Correct 1 ms 2652 KB Output is correct
29 Correct 2 ms 2652 KB Output is correct
30 Correct 2 ms 2652 KB Output is correct
31 Correct 1 ms 2652 KB Output is correct
32 Correct 1 ms 2652 KB Output is correct
33 Correct 2 ms 2652 KB Output is correct
34 Correct 2 ms 2652 KB Output is correct
35 Correct 1 ms 2652 KB Output is correct
36 Correct 1 ms 2652 KB Output is correct
37 Correct 1 ms 2652 KB Output is correct
38 Correct 1 ms 2652 KB Output is correct
39 Correct 113 ms 27892 KB Output is correct
40 Correct 97 ms 27724 KB Output is correct
41 Correct 98 ms 27484 KB Output is correct
42 Correct 104 ms 27308 KB Output is correct
43 Correct 118 ms 36792 KB Output is correct
44 Correct 100 ms 29776 KB Output is correct
45 Correct 84 ms 28948 KB Output is correct
46 Correct 50 ms 35920 KB Output is correct
47 Correct 146 ms 41988 KB Output is correct
48 Correct 209 ms 76536 KB Output is correct
49 Correct 216 ms 74832 KB Output is correct
50 Correct 150 ms 42048 KB Output is correct
51 Correct 143 ms 42080 KB Output is correct
52 Correct 206 ms 41976 KB Output is correct
53 Correct 183 ms 45652 KB Output is correct
54 Correct 272 ms 69456 KB Output is correct
55 Correct 12 ms 5468 KB Output is correct
56 Correct 6 ms 4444 KB Output is correct
57 Correct 51 ms 25940 KB Output is correct
58 Correct 41 ms 20928 KB Output is correct
59 Correct 70 ms 40796 KB Output is correct
60 Correct 210 ms 75512 KB Output is correct
61 Correct 171 ms 44636 KB Output is correct
62 Correct 141 ms 42064 KB Output is correct
63 Correct 184 ms 41976 KB Output is correct
64 Correct 369 ms 83084 KB Output is correct
65 Correct 357 ms 81360 KB Output is correct
66 Correct 237 ms 71248 KB Output is correct
67 Correct 130 ms 37824 KB Output is correct
68 Correct 280 ms 54540 KB Output is correct
69 Correct 311 ms 58216 KB Output is correct
70 Correct 264 ms 52188 KB Output is correct