# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
379296 |
2021-03-17T22:03:48 Z |
justiny7 |
Race (IOI11_race) |
C++17 |
|
1118 ms |
38880 KB |
//#include "race.h"
#include <bits/stdc++.h>
using namespace std;
const int mxN=2e5+1, INF=1e9;
int k, ans=INF, sz[mxN];
vector<pair<int, int>> adj[mxN], vals;
map<int, int> mn;
bool vis[mxN];
int dfs_sz(int v, int p=-1) {
sz[v]=1;
for (auto [u, d]:adj[v])
if (!vis[u] && u^p)
sz[v]+=dfs_sz(u, v);
return sz[v];
}
int dfs_centroid(int tot, int v, int p=-1) {
for (auto [u, d]:adj[v])
if (!vis[u] && u^p && sz[u]*2>tot)
return dfs_centroid(tot, u, v);
return v;
}
void dfs(int v, int len, int p=-1, int dep=1) {
vals.emplace_back(dep, len);
for (auto [u, d]:adj[v])
if (!vis[u] && u^p && len+d<=k)
dfs(u, len+d, v, dep+1);
}
void decomp(int x=0) {
int v=dfs_centroid(dfs_sz(x), x);
vis[v]=1;
mn.clear();
mn[0]=0;
for (auto [u, d]:adj[v]) {
if (vis[u])
continue;
vals.clear();
dfs(u, d);
for (auto [dep, len]:vals)
if (mn.count(k-len))
ans=min(ans, dep+mn[k-len]);
for (auto [dep, len]:vals) {
if (mn.count(len))
mn[len]=min(mn[len], dep);
else
mn[len]=dep;
}
}
for (auto [u, d]:adj[v])
if (!vis[u])
decomp(u);
}
int best_path(int N, int K, int H[][2], int L[]) {
k=K;
for (int i=0; i<N; ++i)
adj[i].clear();
for (int i=0; i<N-1; ++i) {
adj[H[i][0]].emplace_back(H[i][1], L[i]);
adj[H[i][1]].emplace_back(H[i][0], L[i]);
}
decomp();
return (ans==INF?-1:ans);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
5100 KB |
Output is correct |
2 |
Correct |
4 ms |
5100 KB |
Output is correct |
3 |
Correct |
4 ms |
5100 KB |
Output is correct |
4 |
Correct |
4 ms |
5100 KB |
Output is correct |
5 |
Correct |
4 ms |
5100 KB |
Output is correct |
6 |
Correct |
4 ms |
5100 KB |
Output is correct |
7 |
Correct |
4 ms |
5100 KB |
Output is correct |
8 |
Correct |
4 ms |
5100 KB |
Output is correct |
9 |
Correct |
4 ms |
5100 KB |
Output is correct |
10 |
Correct |
4 ms |
5100 KB |
Output is correct |
11 |
Correct |
4 ms |
5100 KB |
Output is correct |
12 |
Correct |
4 ms |
5228 KB |
Output is correct |
13 |
Correct |
4 ms |
5100 KB |
Output is correct |
14 |
Correct |
4 ms |
5100 KB |
Output is correct |
15 |
Correct |
4 ms |
5100 KB |
Output is correct |
16 |
Correct |
4 ms |
5100 KB |
Output is correct |
17 |
Correct |
4 ms |
5100 KB |
Output is correct |
18 |
Correct |
4 ms |
5100 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
5100 KB |
Output is correct |
2 |
Correct |
4 ms |
5100 KB |
Output is correct |
3 |
Correct |
4 ms |
5100 KB |
Output is correct |
4 |
Correct |
4 ms |
5100 KB |
Output is correct |
5 |
Correct |
4 ms |
5100 KB |
Output is correct |
6 |
Correct |
4 ms |
5100 KB |
Output is correct |
7 |
Correct |
4 ms |
5100 KB |
Output is correct |
8 |
Correct |
4 ms |
5100 KB |
Output is correct |
9 |
Correct |
4 ms |
5100 KB |
Output is correct |
10 |
Correct |
4 ms |
5100 KB |
Output is correct |
11 |
Correct |
4 ms |
5100 KB |
Output is correct |
12 |
Correct |
4 ms |
5228 KB |
Output is correct |
13 |
Correct |
4 ms |
5100 KB |
Output is correct |
14 |
Correct |
4 ms |
5100 KB |
Output is correct |
15 |
Correct |
4 ms |
5100 KB |
Output is correct |
16 |
Correct |
4 ms |
5100 KB |
Output is correct |
17 |
Correct |
4 ms |
5100 KB |
Output is correct |
18 |
Correct |
4 ms |
5100 KB |
Output is correct |
19 |
Correct |
4 ms |
5228 KB |
Output is correct |
20 |
Correct |
4 ms |
5100 KB |
Output is correct |
21 |
Correct |
5 ms |
5100 KB |
Output is correct |
22 |
Correct |
4 ms |
5100 KB |
Output is correct |
23 |
Correct |
4 ms |
5100 KB |
Output is correct |
24 |
Correct |
4 ms |
5100 KB |
Output is correct |
25 |
Correct |
5 ms |
5100 KB |
Output is correct |
26 |
Correct |
6 ms |
5100 KB |
Output is correct |
27 |
Correct |
5 ms |
5100 KB |
Output is correct |
28 |
Correct |
5 ms |
5100 KB |
Output is correct |
29 |
Correct |
5 ms |
5100 KB |
Output is correct |
30 |
Correct |
5 ms |
5100 KB |
Output is correct |
31 |
Correct |
5 ms |
5100 KB |
Output is correct |
32 |
Correct |
5 ms |
5100 KB |
Output is correct |
33 |
Correct |
7 ms |
5100 KB |
Output is correct |
34 |
Correct |
6 ms |
5100 KB |
Output is correct |
35 |
Correct |
6 ms |
5100 KB |
Output is correct |
36 |
Correct |
5 ms |
5100 KB |
Output is correct |
37 |
Correct |
5 ms |
5100 KB |
Output is correct |
38 |
Correct |
5 ms |
5100 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
5100 KB |
Output is correct |
2 |
Correct |
4 ms |
5100 KB |
Output is correct |
3 |
Correct |
4 ms |
5100 KB |
Output is correct |
4 |
Correct |
4 ms |
5100 KB |
Output is correct |
5 |
Correct |
4 ms |
5100 KB |
Output is correct |
6 |
Correct |
4 ms |
5100 KB |
Output is correct |
7 |
Correct |
4 ms |
5100 KB |
Output is correct |
8 |
Correct |
4 ms |
5100 KB |
Output is correct |
9 |
Correct |
4 ms |
5100 KB |
Output is correct |
10 |
Correct |
4 ms |
5100 KB |
Output is correct |
11 |
Correct |
4 ms |
5100 KB |
Output is correct |
12 |
Correct |
4 ms |
5228 KB |
Output is correct |
13 |
Correct |
4 ms |
5100 KB |
Output is correct |
14 |
Correct |
4 ms |
5100 KB |
Output is correct |
15 |
Correct |
4 ms |
5100 KB |
Output is correct |
16 |
Correct |
4 ms |
5100 KB |
Output is correct |
17 |
Correct |
4 ms |
5100 KB |
Output is correct |
18 |
Correct |
4 ms |
5100 KB |
Output is correct |
19 |
Correct |
229 ms |
11884 KB |
Output is correct |
20 |
Correct |
220 ms |
11756 KB |
Output is correct |
21 |
Correct |
251 ms |
12016 KB |
Output is correct |
22 |
Correct |
270 ms |
12264 KB |
Output is correct |
23 |
Correct |
109 ms |
12140 KB |
Output is correct |
24 |
Correct |
112 ms |
11884 KB |
Output is correct |
25 |
Correct |
163 ms |
14444 KB |
Output is correct |
26 |
Correct |
118 ms |
18032 KB |
Output is correct |
27 |
Correct |
267 ms |
18796 KB |
Output is correct |
28 |
Correct |
329 ms |
30220 KB |
Output is correct |
29 |
Correct |
334 ms |
29544 KB |
Output is correct |
30 |
Correct |
273 ms |
18796 KB |
Output is correct |
31 |
Correct |
253 ms |
18924 KB |
Output is correct |
32 |
Correct |
300 ms |
19120 KB |
Output is correct |
33 |
Correct |
355 ms |
17832 KB |
Output is correct |
34 |
Correct |
238 ms |
18540 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
5100 KB |
Output is correct |
2 |
Correct |
4 ms |
5100 KB |
Output is correct |
3 |
Correct |
4 ms |
5100 KB |
Output is correct |
4 |
Correct |
4 ms |
5100 KB |
Output is correct |
5 |
Correct |
4 ms |
5100 KB |
Output is correct |
6 |
Correct |
4 ms |
5100 KB |
Output is correct |
7 |
Correct |
4 ms |
5100 KB |
Output is correct |
8 |
Correct |
4 ms |
5100 KB |
Output is correct |
9 |
Correct |
4 ms |
5100 KB |
Output is correct |
10 |
Correct |
4 ms |
5100 KB |
Output is correct |
11 |
Correct |
4 ms |
5100 KB |
Output is correct |
12 |
Correct |
4 ms |
5228 KB |
Output is correct |
13 |
Correct |
4 ms |
5100 KB |
Output is correct |
14 |
Correct |
4 ms |
5100 KB |
Output is correct |
15 |
Correct |
4 ms |
5100 KB |
Output is correct |
16 |
Correct |
4 ms |
5100 KB |
Output is correct |
17 |
Correct |
4 ms |
5100 KB |
Output is correct |
18 |
Correct |
4 ms |
5100 KB |
Output is correct |
19 |
Correct |
4 ms |
5228 KB |
Output is correct |
20 |
Correct |
4 ms |
5100 KB |
Output is correct |
21 |
Correct |
5 ms |
5100 KB |
Output is correct |
22 |
Correct |
4 ms |
5100 KB |
Output is correct |
23 |
Correct |
4 ms |
5100 KB |
Output is correct |
24 |
Correct |
4 ms |
5100 KB |
Output is correct |
25 |
Correct |
5 ms |
5100 KB |
Output is correct |
26 |
Correct |
6 ms |
5100 KB |
Output is correct |
27 |
Correct |
5 ms |
5100 KB |
Output is correct |
28 |
Correct |
5 ms |
5100 KB |
Output is correct |
29 |
Correct |
5 ms |
5100 KB |
Output is correct |
30 |
Correct |
5 ms |
5100 KB |
Output is correct |
31 |
Correct |
5 ms |
5100 KB |
Output is correct |
32 |
Correct |
5 ms |
5100 KB |
Output is correct |
33 |
Correct |
7 ms |
5100 KB |
Output is correct |
34 |
Correct |
6 ms |
5100 KB |
Output is correct |
35 |
Correct |
6 ms |
5100 KB |
Output is correct |
36 |
Correct |
5 ms |
5100 KB |
Output is correct |
37 |
Correct |
5 ms |
5100 KB |
Output is correct |
38 |
Correct |
5 ms |
5100 KB |
Output is correct |
39 |
Correct |
229 ms |
11884 KB |
Output is correct |
40 |
Correct |
220 ms |
11756 KB |
Output is correct |
41 |
Correct |
251 ms |
12016 KB |
Output is correct |
42 |
Correct |
270 ms |
12264 KB |
Output is correct |
43 |
Correct |
109 ms |
12140 KB |
Output is correct |
44 |
Correct |
112 ms |
11884 KB |
Output is correct |
45 |
Correct |
163 ms |
14444 KB |
Output is correct |
46 |
Correct |
118 ms |
18032 KB |
Output is correct |
47 |
Correct |
267 ms |
18796 KB |
Output is correct |
48 |
Correct |
329 ms |
30220 KB |
Output is correct |
49 |
Correct |
334 ms |
29544 KB |
Output is correct |
50 |
Correct |
273 ms |
18796 KB |
Output is correct |
51 |
Correct |
253 ms |
18924 KB |
Output is correct |
52 |
Correct |
300 ms |
19120 KB |
Output is correct |
53 |
Correct |
355 ms |
17832 KB |
Output is correct |
54 |
Correct |
238 ms |
18540 KB |
Output is correct |
55 |
Correct |
23 ms |
5888 KB |
Output is correct |
56 |
Correct |
17 ms |
5740 KB |
Output is correct |
57 |
Correct |
154 ms |
12524 KB |
Output is correct |
58 |
Correct |
59 ms |
11616 KB |
Output is correct |
59 |
Correct |
314 ms |
21484 KB |
Output is correct |
60 |
Correct |
982 ms |
38880 KB |
Output is correct |
61 |
Correct |
333 ms |
19328 KB |
Output is correct |
62 |
Correct |
342 ms |
19180 KB |
Output is correct |
63 |
Correct |
416 ms |
19068 KB |
Output is correct |
64 |
Correct |
1118 ms |
24544 KB |
Output is correct |
65 |
Correct |
304 ms |
19756 KB |
Output is correct |
66 |
Correct |
655 ms |
27628 KB |
Output is correct |
67 |
Correct |
163 ms |
19548 KB |
Output is correct |
68 |
Correct |
496 ms |
23276 KB |
Output is correct |
69 |
Correct |
554 ms |
23276 KB |
Output is correct |
70 |
Correct |
452 ms |
22508 KB |
Output is correct |