# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
701383 |
2023-02-21T06:29:59 Z |
mychecksedad |
Race (IOI11_race) |
C++17 |
|
819 ms |
71272 KB |
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int M = 1e6;
#define pb push_back
struct Edge{
int to, e;
};
int n, k, ans, s[M];
vector<Edge> g[M];
vector<bool> vis;
int pre(int v, int p){
s[v] = 1;
for(Edge U: g[v]){
int u = U.to;
if(!vis[u] && u != p) pre(u, v), s[v] += s[u];
}
return s[v];
}
int centro(int v, int p, int sz){
for(Edge U: g[v]){
int u = U.to;
if(u != p && !vis[u] && s[u] * 2 > sz)
return centro(u, v, sz);
}
return v;
}
vector<pair<int, int>> ddd;
void dfs(int v, int p, map<int, int> &S, int d, int dd){
ddd.pb({d, dd});
if(d == k){
ans = min(ans, dd);
}
if(d <= k && S.find(k - d) != S.end())
ans = min(ans, dd + S[k - d]);
for(Edge U: g[v]){
int u = U.to;
if(!vis[u] && u != p)
dfs(u, v, S, min(d + U.e, 1000000000), dd + 1);
}
}
void centroid(int v){
int C = centro(v, 0, pre(v, 0));
map<int, int> s;
for(Edge U: g[C]){
int u = U.to;
if(!vis[u]){
ddd.clear();
dfs(u, C, s, U.e, 1);
for(auto v: ddd) s[v.first] = s[v.first] == 0 ? v.second : min(s[v.first], v.second);
}
}
vis[C] = 1;
for(Edge U: g[C]){
int u = U.to;
if(!vis[u])
centroid(u);
}
}
int best_path(int N, int K, int H[][2], int L[])
{
n = N, k = K, ans = N + 1;
for(int i = 0; i < n - 1; ++i){
g[H[i][0] + 1].pb({H[i][1] + 1, L[i]});
g[H[i][1] + 1].pb({H[i][0] + 1, L[i]});
}
vis.resize(n + 1);
centroid(1);
return (ans == N + 1 ? -1 : ans);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
23764 KB |
Output is correct |
2 |
Correct |
13 ms |
23764 KB |
Output is correct |
3 |
Correct |
12 ms |
23796 KB |
Output is correct |
4 |
Correct |
12 ms |
23764 KB |
Output is correct |
5 |
Correct |
12 ms |
23820 KB |
Output is correct |
6 |
Correct |
13 ms |
23764 KB |
Output is correct |
7 |
Correct |
12 ms |
23764 KB |
Output is correct |
8 |
Correct |
13 ms |
23820 KB |
Output is correct |
9 |
Correct |
13 ms |
23796 KB |
Output is correct |
10 |
Correct |
12 ms |
23764 KB |
Output is correct |
11 |
Correct |
15 ms |
23748 KB |
Output is correct |
12 |
Correct |
13 ms |
23804 KB |
Output is correct |
13 |
Correct |
13 ms |
23764 KB |
Output is correct |
14 |
Correct |
13 ms |
23796 KB |
Output is correct |
15 |
Correct |
15 ms |
23764 KB |
Output is correct |
16 |
Correct |
13 ms |
23796 KB |
Output is correct |
17 |
Correct |
13 ms |
23764 KB |
Output is correct |
18 |
Correct |
13 ms |
23796 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
23764 KB |
Output is correct |
2 |
Correct |
13 ms |
23764 KB |
Output is correct |
3 |
Correct |
12 ms |
23796 KB |
Output is correct |
4 |
Correct |
12 ms |
23764 KB |
Output is correct |
5 |
Correct |
12 ms |
23820 KB |
Output is correct |
6 |
Correct |
13 ms |
23764 KB |
Output is correct |
7 |
Correct |
12 ms |
23764 KB |
Output is correct |
8 |
Correct |
13 ms |
23820 KB |
Output is correct |
9 |
Correct |
13 ms |
23796 KB |
Output is correct |
10 |
Correct |
12 ms |
23764 KB |
Output is correct |
11 |
Correct |
15 ms |
23748 KB |
Output is correct |
12 |
Correct |
13 ms |
23804 KB |
Output is correct |
13 |
Correct |
13 ms |
23764 KB |
Output is correct |
14 |
Correct |
13 ms |
23796 KB |
Output is correct |
15 |
Correct |
15 ms |
23764 KB |
Output is correct |
16 |
Correct |
13 ms |
23796 KB |
Output is correct |
17 |
Correct |
13 ms |
23764 KB |
Output is correct |
18 |
Correct |
13 ms |
23796 KB |
Output is correct |
19 |
Correct |
12 ms |
23696 KB |
Output is correct |
20 |
Correct |
12 ms |
23768 KB |
Output is correct |
21 |
Correct |
13 ms |
23872 KB |
Output is correct |
22 |
Correct |
14 ms |
23912 KB |
Output is correct |
23 |
Correct |
15 ms |
23936 KB |
Output is correct |
24 |
Correct |
13 ms |
23892 KB |
Output is correct |
25 |
Correct |
15 ms |
23944 KB |
Output is correct |
26 |
Correct |
16 ms |
23840 KB |
Output is correct |
27 |
Correct |
13 ms |
23872 KB |
Output is correct |
28 |
Correct |
14 ms |
23924 KB |
Output is correct |
29 |
Correct |
14 ms |
23892 KB |
Output is correct |
30 |
Correct |
13 ms |
23936 KB |
Output is correct |
31 |
Correct |
15 ms |
23892 KB |
Output is correct |
32 |
Correct |
14 ms |
23848 KB |
Output is correct |
33 |
Correct |
14 ms |
23892 KB |
Output is correct |
34 |
Correct |
17 ms |
23932 KB |
Output is correct |
35 |
Correct |
13 ms |
23936 KB |
Output is correct |
36 |
Correct |
14 ms |
23936 KB |
Output is correct |
37 |
Correct |
12 ms |
23864 KB |
Output is correct |
38 |
Correct |
13 ms |
23892 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
23764 KB |
Output is correct |
2 |
Correct |
13 ms |
23764 KB |
Output is correct |
3 |
Correct |
12 ms |
23796 KB |
Output is correct |
4 |
Correct |
12 ms |
23764 KB |
Output is correct |
5 |
Correct |
12 ms |
23820 KB |
Output is correct |
6 |
Correct |
13 ms |
23764 KB |
Output is correct |
7 |
Correct |
12 ms |
23764 KB |
Output is correct |
8 |
Correct |
13 ms |
23820 KB |
Output is correct |
9 |
Correct |
13 ms |
23796 KB |
Output is correct |
10 |
Correct |
12 ms |
23764 KB |
Output is correct |
11 |
Correct |
15 ms |
23748 KB |
Output is correct |
12 |
Correct |
13 ms |
23804 KB |
Output is correct |
13 |
Correct |
13 ms |
23764 KB |
Output is correct |
14 |
Correct |
13 ms |
23796 KB |
Output is correct |
15 |
Correct |
15 ms |
23764 KB |
Output is correct |
16 |
Correct |
13 ms |
23796 KB |
Output is correct |
17 |
Correct |
13 ms |
23764 KB |
Output is correct |
18 |
Correct |
13 ms |
23796 KB |
Output is correct |
19 |
Correct |
217 ms |
30972 KB |
Output is correct |
20 |
Correct |
219 ms |
30912 KB |
Output is correct |
21 |
Correct |
224 ms |
30992 KB |
Output is correct |
22 |
Correct |
215 ms |
31116 KB |
Output is correct |
23 |
Correct |
262 ms |
31436 KB |
Output is correct |
24 |
Correct |
150 ms |
30904 KB |
Output is correct |
25 |
Correct |
236 ms |
36240 KB |
Output is correct |
26 |
Correct |
115 ms |
38368 KB |
Output is correct |
27 |
Correct |
293 ms |
37712 KB |
Output is correct |
28 |
Correct |
758 ms |
71272 KB |
Output is correct |
29 |
Correct |
794 ms |
70176 KB |
Output is correct |
30 |
Correct |
278 ms |
37656 KB |
Output is correct |
31 |
Correct |
278 ms |
37688 KB |
Output is correct |
32 |
Correct |
328 ms |
37752 KB |
Output is correct |
33 |
Correct |
448 ms |
37592 KB |
Output is correct |
34 |
Correct |
679 ms |
54292 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
23764 KB |
Output is correct |
2 |
Correct |
13 ms |
23764 KB |
Output is correct |
3 |
Correct |
12 ms |
23796 KB |
Output is correct |
4 |
Correct |
12 ms |
23764 KB |
Output is correct |
5 |
Correct |
12 ms |
23820 KB |
Output is correct |
6 |
Correct |
13 ms |
23764 KB |
Output is correct |
7 |
Correct |
12 ms |
23764 KB |
Output is correct |
8 |
Correct |
13 ms |
23820 KB |
Output is correct |
9 |
Correct |
13 ms |
23796 KB |
Output is correct |
10 |
Correct |
12 ms |
23764 KB |
Output is correct |
11 |
Correct |
15 ms |
23748 KB |
Output is correct |
12 |
Correct |
13 ms |
23804 KB |
Output is correct |
13 |
Correct |
13 ms |
23764 KB |
Output is correct |
14 |
Correct |
13 ms |
23796 KB |
Output is correct |
15 |
Correct |
15 ms |
23764 KB |
Output is correct |
16 |
Correct |
13 ms |
23796 KB |
Output is correct |
17 |
Correct |
13 ms |
23764 KB |
Output is correct |
18 |
Correct |
13 ms |
23796 KB |
Output is correct |
19 |
Correct |
12 ms |
23696 KB |
Output is correct |
20 |
Correct |
12 ms |
23768 KB |
Output is correct |
21 |
Correct |
13 ms |
23872 KB |
Output is correct |
22 |
Correct |
14 ms |
23912 KB |
Output is correct |
23 |
Correct |
15 ms |
23936 KB |
Output is correct |
24 |
Correct |
13 ms |
23892 KB |
Output is correct |
25 |
Correct |
15 ms |
23944 KB |
Output is correct |
26 |
Correct |
16 ms |
23840 KB |
Output is correct |
27 |
Correct |
13 ms |
23872 KB |
Output is correct |
28 |
Correct |
14 ms |
23924 KB |
Output is correct |
29 |
Correct |
14 ms |
23892 KB |
Output is correct |
30 |
Correct |
13 ms |
23936 KB |
Output is correct |
31 |
Correct |
15 ms |
23892 KB |
Output is correct |
32 |
Correct |
14 ms |
23848 KB |
Output is correct |
33 |
Correct |
14 ms |
23892 KB |
Output is correct |
34 |
Correct |
17 ms |
23932 KB |
Output is correct |
35 |
Correct |
13 ms |
23936 KB |
Output is correct |
36 |
Correct |
14 ms |
23936 KB |
Output is correct |
37 |
Correct |
12 ms |
23864 KB |
Output is correct |
38 |
Correct |
13 ms |
23892 KB |
Output is correct |
39 |
Correct |
217 ms |
30972 KB |
Output is correct |
40 |
Correct |
219 ms |
30912 KB |
Output is correct |
41 |
Correct |
224 ms |
30992 KB |
Output is correct |
42 |
Correct |
215 ms |
31116 KB |
Output is correct |
43 |
Correct |
262 ms |
31436 KB |
Output is correct |
44 |
Correct |
150 ms |
30904 KB |
Output is correct |
45 |
Correct |
236 ms |
36240 KB |
Output is correct |
46 |
Correct |
115 ms |
38368 KB |
Output is correct |
47 |
Correct |
293 ms |
37712 KB |
Output is correct |
48 |
Correct |
758 ms |
71272 KB |
Output is correct |
49 |
Correct |
794 ms |
70176 KB |
Output is correct |
50 |
Correct |
278 ms |
37656 KB |
Output is correct |
51 |
Correct |
278 ms |
37688 KB |
Output is correct |
52 |
Correct |
328 ms |
37752 KB |
Output is correct |
53 |
Correct |
448 ms |
37592 KB |
Output is correct |
54 |
Correct |
679 ms |
54292 KB |
Output is correct |
55 |
Correct |
32 ms |
25040 KB |
Output is correct |
56 |
Correct |
23 ms |
24532 KB |
Output is correct |
57 |
Correct |
138 ms |
31308 KB |
Output is correct |
58 |
Correct |
52 ms |
30316 KB |
Output is correct |
59 |
Correct |
290 ms |
45132 KB |
Output is correct |
60 |
Correct |
765 ms |
68924 KB |
Output is correct |
61 |
Correct |
328 ms |
38972 KB |
Output is correct |
62 |
Correct |
303 ms |
37708 KB |
Output is correct |
63 |
Correct |
330 ms |
37744 KB |
Output is correct |
64 |
Correct |
819 ms |
49536 KB |
Output is correct |
65 |
Correct |
726 ms |
55408 KB |
Output is correct |
66 |
Correct |
791 ms |
67756 KB |
Output is correct |
67 |
Correct |
143 ms |
38128 KB |
Output is correct |
68 |
Correct |
444 ms |
50752 KB |
Output is correct |
69 |
Correct |
470 ms |
51404 KB |
Output is correct |
70 |
Correct |
429 ms |
49584 KB |
Output is correct |