Submission #659861

# Submission time Handle Problem Language Result Execution time Memory
659861 2022-11-19T14:24:15 Z Trisanu_Das Race (IOI11_race) C++17
100 / 100
419 ms 88012 KB
#include <bits/stdc++.h>
using namespace std; 
int K, ans = INT_MAX; vector<pair<int, int>> adj[200005]; set<pair<int, int>> S[200005];
 
void dfs(int u, int p, int dis, int dep){
    S[u].insert({dis, dep});
    for (auto v : adj[u]) if (v.first != p){
        dfs(v.first, u, dis + v.second, dep + 1);
        if (S[u].size() < S[v.first].size()) swap(S[u], S[v.first]);
        for (auto d : S[v.first]){
            int other = K + 2 * dis - d.first; auto x = S[u].lower_bound({other, -1});
            if (x != S[u].end() and (*x).first == other) ans = min(ans, d.second + (*x).second - 2 * dep);
        }for (auto d : S[v.first]) S[u].insert(d);
    }
}
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]});
    }K = k; dfs(0, 0, 0, 0); return (ans == INT_MAX) ? -1 : ans;
}
# Verdict Execution time Memory Grader output
1 Correct 8 ms 14380 KB Output is correct
2 Correct 8 ms 14396 KB Output is correct
3 Correct 8 ms 14396 KB Output is correct
4 Correct 8 ms 14440 KB Output is correct
5 Correct 8 ms 14404 KB Output is correct
6 Correct 9 ms 14440 KB Output is correct
7 Correct 9 ms 14420 KB Output is correct
8 Correct 9 ms 14400 KB Output is correct
9 Correct 8 ms 14404 KB Output is correct
10 Correct 10 ms 14420 KB Output is correct
11 Correct 8 ms 14420 KB Output is correct
12 Correct 7 ms 14420 KB Output is correct
13 Correct 8 ms 14312 KB Output is correct
14 Correct 8 ms 14400 KB Output is correct
15 Correct 7 ms 14420 KB Output is correct
16 Correct 8 ms 14420 KB Output is correct
17 Correct 8 ms 14420 KB Output is correct
18 Correct 9 ms 14420 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 14380 KB Output is correct
2 Correct 8 ms 14396 KB Output is correct
3 Correct 8 ms 14396 KB Output is correct
4 Correct 8 ms 14440 KB Output is correct
5 Correct 8 ms 14404 KB Output is correct
6 Correct 9 ms 14440 KB Output is correct
7 Correct 9 ms 14420 KB Output is correct
8 Correct 9 ms 14400 KB Output is correct
9 Correct 8 ms 14404 KB Output is correct
10 Correct 10 ms 14420 KB Output is correct
11 Correct 8 ms 14420 KB Output is correct
12 Correct 7 ms 14420 KB Output is correct
13 Correct 8 ms 14312 KB Output is correct
14 Correct 8 ms 14400 KB Output is correct
15 Correct 7 ms 14420 KB Output is correct
16 Correct 8 ms 14420 KB Output is correct
17 Correct 8 ms 14420 KB Output is correct
18 Correct 9 ms 14420 KB Output is correct
19 Correct 9 ms 14292 KB Output is correct
20 Correct 8 ms 14420 KB Output is correct
21 Correct 9 ms 14548 KB Output is correct
22 Correct 9 ms 14664 KB Output is correct
23 Correct 10 ms 14644 KB Output is correct
24 Correct 8 ms 14548 KB Output is correct
25 Correct 8 ms 14548 KB Output is correct
26 Correct 9 ms 14548 KB Output is correct
27 Correct 9 ms 14540 KB Output is correct
28 Correct 9 ms 14548 KB Output is correct
29 Correct 9 ms 14548 KB Output is correct
30 Correct 9 ms 14604 KB Output is correct
31 Correct 8 ms 14540 KB Output is correct
32 Correct 8 ms 14548 KB Output is correct
33 Correct 9 ms 14668 KB Output is correct
34 Correct 9 ms 14548 KB Output is correct
35 Correct 9 ms 14536 KB Output is correct
36 Correct 8 ms 14548 KB Output is correct
37 Correct 8 ms 14548 KB Output is correct
38 Correct 9 ms 14532 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 14380 KB Output is correct
2 Correct 8 ms 14396 KB Output is correct
3 Correct 8 ms 14396 KB Output is correct
4 Correct 8 ms 14440 KB Output is correct
5 Correct 8 ms 14404 KB Output is correct
6 Correct 9 ms 14440 KB Output is correct
7 Correct 9 ms 14420 KB Output is correct
8 Correct 9 ms 14400 KB Output is correct
9 Correct 8 ms 14404 KB Output is correct
10 Correct 10 ms 14420 KB Output is correct
11 Correct 8 ms 14420 KB Output is correct
12 Correct 7 ms 14420 KB Output is correct
13 Correct 8 ms 14312 KB Output is correct
14 Correct 8 ms 14400 KB Output is correct
15 Correct 7 ms 14420 KB Output is correct
16 Correct 8 ms 14420 KB Output is correct
17 Correct 8 ms 14420 KB Output is correct
18 Correct 9 ms 14420 KB Output is correct
19 Correct 150 ms 35888 KB Output is correct
20 Correct 126 ms 35900 KB Output is correct
21 Correct 143 ms 35404 KB Output is correct
22 Correct 124 ms 34356 KB Output is correct
23 Correct 167 ms 45184 KB Output is correct
24 Correct 142 ms 35264 KB Output is correct
25 Correct 118 ms 38976 KB Output is correct
26 Correct 79 ms 43424 KB Output is correct
27 Correct 203 ms 43792 KB Output is correct
28 Correct 279 ms 73068 KB Output is correct
29 Correct 255 ms 71620 KB Output is correct
30 Correct 217 ms 43848 KB Output is correct
31 Correct 268 ms 43760 KB Output is correct
32 Correct 261 ms 43964 KB Output is correct
33 Correct 224 ms 45072 KB Output is correct
34 Correct 327 ms 69848 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 14380 KB Output is correct
2 Correct 8 ms 14396 KB Output is correct
3 Correct 8 ms 14396 KB Output is correct
4 Correct 8 ms 14440 KB Output is correct
5 Correct 8 ms 14404 KB Output is correct
6 Correct 9 ms 14440 KB Output is correct
7 Correct 9 ms 14420 KB Output is correct
8 Correct 9 ms 14400 KB Output is correct
9 Correct 8 ms 14404 KB Output is correct
10 Correct 10 ms 14420 KB Output is correct
11 Correct 8 ms 14420 KB Output is correct
12 Correct 7 ms 14420 KB Output is correct
13 Correct 8 ms 14312 KB Output is correct
14 Correct 8 ms 14400 KB Output is correct
15 Correct 7 ms 14420 KB Output is correct
16 Correct 8 ms 14420 KB Output is correct
17 Correct 8 ms 14420 KB Output is correct
18 Correct 9 ms 14420 KB Output is correct
19 Correct 9 ms 14292 KB Output is correct
20 Correct 8 ms 14420 KB Output is correct
21 Correct 9 ms 14548 KB Output is correct
22 Correct 9 ms 14664 KB Output is correct
23 Correct 10 ms 14644 KB Output is correct
24 Correct 8 ms 14548 KB Output is correct
25 Correct 8 ms 14548 KB Output is correct
26 Correct 9 ms 14548 KB Output is correct
27 Correct 9 ms 14540 KB Output is correct
28 Correct 9 ms 14548 KB Output is correct
29 Correct 9 ms 14548 KB Output is correct
30 Correct 9 ms 14604 KB Output is correct
31 Correct 8 ms 14540 KB Output is correct
32 Correct 8 ms 14548 KB Output is correct
33 Correct 9 ms 14668 KB Output is correct
34 Correct 9 ms 14548 KB Output is correct
35 Correct 9 ms 14536 KB Output is correct
36 Correct 8 ms 14548 KB Output is correct
37 Correct 8 ms 14548 KB Output is correct
38 Correct 9 ms 14532 KB Output is correct
39 Correct 150 ms 35888 KB Output is correct
40 Correct 126 ms 35900 KB Output is correct
41 Correct 143 ms 35404 KB Output is correct
42 Correct 124 ms 34356 KB Output is correct
43 Correct 167 ms 45184 KB Output is correct
44 Correct 142 ms 35264 KB Output is correct
45 Correct 118 ms 38976 KB Output is correct
46 Correct 79 ms 43424 KB Output is correct
47 Correct 203 ms 43792 KB Output is correct
48 Correct 279 ms 73068 KB Output is correct
49 Correct 255 ms 71620 KB Output is correct
50 Correct 217 ms 43848 KB Output is correct
51 Correct 268 ms 43760 KB Output is correct
52 Correct 261 ms 43964 KB Output is correct
53 Correct 224 ms 45072 KB Output is correct
54 Correct 327 ms 69848 KB Output is correct
55 Correct 20 ms 16972 KB Output is correct
56 Correct 16 ms 16084 KB Output is correct
57 Correct 88 ms 31880 KB Output is correct
58 Correct 47 ms 25136 KB Output is correct
59 Correct 72 ms 43492 KB Output is correct
60 Correct 230 ms 71888 KB Output is correct
61 Correct 216 ms 48220 KB Output is correct
62 Correct 220 ms 43980 KB Output is correct
63 Correct 249 ms 43980 KB Output is correct
64 Correct 394 ms 88012 KB Output is correct
65 Correct 419 ms 81908 KB Output is correct
66 Correct 258 ms 68756 KB Output is correct
67 Correct 151 ms 37680 KB Output is correct
68 Correct 359 ms 55772 KB Output is correct
69 Correct 336 ms 60020 KB Output is correct
70 Correct 293 ms 54048 KB Output is correct