# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1087322 |
2024-09-12T13:33:36 Z |
quangminh412 |
Race (IOI11_race) |
C++14 |
|
3000 ms |
30028 KB |
#include <bits/stdc++.h>
using namespace std;
/*
John Watson
https://codeforces.com/profile/quangminh98
Mua Code nhu mua Florentino !!
*/
#define faster() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long
const int oo = 1e9;
const int maxn = 2e5 + 9;
vector<pair<int, int>> adj[maxn];
int del[maxn], sz[maxn], h[maxn];
vector<int> cnt;
int n, k, res = oo;
int subtree(int u, int p = -1)
{
sz[u] = 1;
for (pair<int, int> nxt : adj[u])
{
int v = nxt.first;
if (v == p || del[v]) continue;
sz[u] += subtree(v, u);
}
return sz[u];
}
int find_centroid(int u, int p, int N)
{
for (pair<int, int> nxt : adj[u])
{
int v = nxt.first;
if (v == p || del[v]) continue;
if (sz[v] > N / 2)
return find_centroid(v, u, N);
}
return u;
}
void count(int u, int p, int w, int h)
{
if (w > k) return;
if (cnt[k - w] != oo)
res = min(res, cnt[k - w] + h);
for (pair<int, int> nxt : adj[u])
{
int v = nxt.first;
if (del[v] || v == p) continue;
count(v, u, w + nxt.second, h + 1);
}
}
void update(int u, int p, int w, int h)
{
if (w > k) return;
cnt[w] = min(cnt[w], h);
for (pair<int, int> nxt : adj[u])
{
int v = nxt.first;
if (del[v] || v == p) continue;
update(v, u, w + nxt.second, h + 1);
}
}
void centroid_decomposition(int u)
{
int centroid = find_centroid(u, -1, subtree(u));
del[centroid] = 1;
for (int i = 1; i <= k; i++) cnt[i] = oo;
for (pair<int, int> nxt : adj[centroid])
{
int v = nxt.first;
if (del[v]) continue;
count(v, centroid, nxt.second, 1);
update(v, centroid, nxt.second, 1);
}
for (pair<int, int> nxt : adj[centroid])
{
int v = nxt.first;
if (del[v]) continue;
centroid_decomposition(v);
}
}
int best_path(int _n, int _k, int H[][2], int l[])
{
n = _n;
k = _k;
cnt.resize(k + 5, oo);
cnt[0] = 0;
for (int i = 0; i < n - 1; i++)
{
int w = l[i];
int u = H[i][0], v = H[i][1];
adj[u].push_back({v, w});
adj[v].push_back({u, w});
}
centroid_decomposition(1);
return (res == oo ? -1 : res);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4952 KB |
Output is correct |
2 |
Correct |
2 ms |
4956 KB |
Output is correct |
3 |
Correct |
2 ms |
5048 KB |
Output is correct |
4 |
Correct |
2 ms |
5064 KB |
Output is correct |
5 |
Correct |
2 ms |
4956 KB |
Output is correct |
6 |
Correct |
2 ms |
4956 KB |
Output is correct |
7 |
Correct |
2 ms |
4952 KB |
Output is correct |
8 |
Correct |
2 ms |
4956 KB |
Output is correct |
9 |
Correct |
2 ms |
4964 KB |
Output is correct |
10 |
Correct |
2 ms |
4952 KB |
Output is correct |
11 |
Correct |
4 ms |
4956 KB |
Output is correct |
12 |
Correct |
4 ms |
4956 KB |
Output is correct |
13 |
Correct |
2 ms |
4956 KB |
Output is correct |
14 |
Correct |
2 ms |
4956 KB |
Output is correct |
15 |
Correct |
3 ms |
4956 KB |
Output is correct |
16 |
Correct |
2 ms |
4956 KB |
Output is correct |
17 |
Correct |
2 ms |
4956 KB |
Output is correct |
18 |
Correct |
3 ms |
4956 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4952 KB |
Output is correct |
2 |
Correct |
2 ms |
4956 KB |
Output is correct |
3 |
Correct |
2 ms |
5048 KB |
Output is correct |
4 |
Correct |
2 ms |
5064 KB |
Output is correct |
5 |
Correct |
2 ms |
4956 KB |
Output is correct |
6 |
Correct |
2 ms |
4956 KB |
Output is correct |
7 |
Correct |
2 ms |
4952 KB |
Output is correct |
8 |
Correct |
2 ms |
4956 KB |
Output is correct |
9 |
Correct |
2 ms |
4964 KB |
Output is correct |
10 |
Correct |
2 ms |
4952 KB |
Output is correct |
11 |
Correct |
4 ms |
4956 KB |
Output is correct |
12 |
Correct |
4 ms |
4956 KB |
Output is correct |
13 |
Correct |
2 ms |
4956 KB |
Output is correct |
14 |
Correct |
2 ms |
4956 KB |
Output is correct |
15 |
Correct |
3 ms |
4956 KB |
Output is correct |
16 |
Correct |
2 ms |
4956 KB |
Output is correct |
17 |
Correct |
2 ms |
4956 KB |
Output is correct |
18 |
Correct |
3 ms |
4956 KB |
Output is correct |
19 |
Correct |
2 ms |
4952 KB |
Output is correct |
20 |
Correct |
3 ms |
4956 KB |
Output is correct |
21 |
Correct |
3 ms |
5208 KB |
Output is correct |
22 |
Correct |
393 ms |
8844 KB |
Output is correct |
23 |
Correct |
261 ms |
8028 KB |
Output is correct |
24 |
Correct |
368 ms |
8788 KB |
Output is correct |
25 |
Correct |
314 ms |
8540 KB |
Output is correct |
26 |
Correct |
124 ms |
6488 KB |
Output is correct |
27 |
Correct |
329 ms |
8532 KB |
Output is correct |
28 |
Correct |
71 ms |
5980 KB |
Output is correct |
29 |
Correct |
149 ms |
6488 KB |
Output is correct |
30 |
Correct |
137 ms |
6736 KB |
Output is correct |
31 |
Correct |
232 ms |
7784 KB |
Output is correct |
32 |
Correct |
267 ms |
7976 KB |
Output is correct |
33 |
Correct |
297 ms |
8284 KB |
Output is correct |
34 |
Correct |
189 ms |
7512 KB |
Output is correct |
35 |
Correct |
262 ms |
8408 KB |
Output is correct |
36 |
Correct |
270 ms |
8868 KB |
Output is correct |
37 |
Correct |
249 ms |
8280 KB |
Output is correct |
38 |
Correct |
167 ms |
7004 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4952 KB |
Output is correct |
2 |
Correct |
2 ms |
4956 KB |
Output is correct |
3 |
Correct |
2 ms |
5048 KB |
Output is correct |
4 |
Correct |
2 ms |
5064 KB |
Output is correct |
5 |
Correct |
2 ms |
4956 KB |
Output is correct |
6 |
Correct |
2 ms |
4956 KB |
Output is correct |
7 |
Correct |
2 ms |
4952 KB |
Output is correct |
8 |
Correct |
2 ms |
4956 KB |
Output is correct |
9 |
Correct |
2 ms |
4964 KB |
Output is correct |
10 |
Correct |
2 ms |
4952 KB |
Output is correct |
11 |
Correct |
4 ms |
4956 KB |
Output is correct |
12 |
Correct |
4 ms |
4956 KB |
Output is correct |
13 |
Correct |
2 ms |
4956 KB |
Output is correct |
14 |
Correct |
2 ms |
4956 KB |
Output is correct |
15 |
Correct |
3 ms |
4956 KB |
Output is correct |
16 |
Correct |
2 ms |
4956 KB |
Output is correct |
17 |
Correct |
2 ms |
4956 KB |
Output is correct |
18 |
Correct |
3 ms |
4956 KB |
Output is correct |
19 |
Correct |
76 ms |
12116 KB |
Output is correct |
20 |
Correct |
75 ms |
12092 KB |
Output is correct |
21 |
Correct |
81 ms |
12008 KB |
Output is correct |
22 |
Correct |
76 ms |
12104 KB |
Output is correct |
23 |
Correct |
55 ms |
12368 KB |
Output is correct |
24 |
Correct |
35 ms |
12112 KB |
Output is correct |
25 |
Correct |
92 ms |
17232 KB |
Output is correct |
26 |
Correct |
60 ms |
17748 KB |
Output is correct |
27 |
Correct |
91 ms |
19428 KB |
Output is correct |
28 |
Correct |
174 ms |
30028 KB |
Output is correct |
29 |
Correct |
146 ms |
25680 KB |
Output is correct |
30 |
Correct |
97 ms |
19284 KB |
Output is correct |
31 |
Correct |
92 ms |
19332 KB |
Output is correct |
32 |
Correct |
127 ms |
19604 KB |
Output is correct |
33 |
Correct |
138 ms |
18244 KB |
Output is correct |
34 |
Correct |
120 ms |
19056 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4952 KB |
Output is correct |
2 |
Correct |
2 ms |
4956 KB |
Output is correct |
3 |
Correct |
2 ms |
5048 KB |
Output is correct |
4 |
Correct |
2 ms |
5064 KB |
Output is correct |
5 |
Correct |
2 ms |
4956 KB |
Output is correct |
6 |
Correct |
2 ms |
4956 KB |
Output is correct |
7 |
Correct |
2 ms |
4952 KB |
Output is correct |
8 |
Correct |
2 ms |
4956 KB |
Output is correct |
9 |
Correct |
2 ms |
4964 KB |
Output is correct |
10 |
Correct |
2 ms |
4952 KB |
Output is correct |
11 |
Correct |
4 ms |
4956 KB |
Output is correct |
12 |
Correct |
4 ms |
4956 KB |
Output is correct |
13 |
Correct |
2 ms |
4956 KB |
Output is correct |
14 |
Correct |
2 ms |
4956 KB |
Output is correct |
15 |
Correct |
3 ms |
4956 KB |
Output is correct |
16 |
Correct |
2 ms |
4956 KB |
Output is correct |
17 |
Correct |
2 ms |
4956 KB |
Output is correct |
18 |
Correct |
3 ms |
4956 KB |
Output is correct |
19 |
Correct |
2 ms |
4952 KB |
Output is correct |
20 |
Correct |
3 ms |
4956 KB |
Output is correct |
21 |
Correct |
3 ms |
5208 KB |
Output is correct |
22 |
Correct |
393 ms |
8844 KB |
Output is correct |
23 |
Correct |
261 ms |
8028 KB |
Output is correct |
24 |
Correct |
368 ms |
8788 KB |
Output is correct |
25 |
Correct |
314 ms |
8540 KB |
Output is correct |
26 |
Correct |
124 ms |
6488 KB |
Output is correct |
27 |
Correct |
329 ms |
8532 KB |
Output is correct |
28 |
Correct |
71 ms |
5980 KB |
Output is correct |
29 |
Correct |
149 ms |
6488 KB |
Output is correct |
30 |
Correct |
137 ms |
6736 KB |
Output is correct |
31 |
Correct |
232 ms |
7784 KB |
Output is correct |
32 |
Correct |
267 ms |
7976 KB |
Output is correct |
33 |
Correct |
297 ms |
8284 KB |
Output is correct |
34 |
Correct |
189 ms |
7512 KB |
Output is correct |
35 |
Correct |
262 ms |
8408 KB |
Output is correct |
36 |
Correct |
270 ms |
8868 KB |
Output is correct |
37 |
Correct |
249 ms |
8280 KB |
Output is correct |
38 |
Correct |
167 ms |
7004 KB |
Output is correct |
39 |
Correct |
76 ms |
12116 KB |
Output is correct |
40 |
Correct |
75 ms |
12092 KB |
Output is correct |
41 |
Correct |
81 ms |
12008 KB |
Output is correct |
42 |
Correct |
76 ms |
12104 KB |
Output is correct |
43 |
Correct |
55 ms |
12368 KB |
Output is correct |
44 |
Correct |
35 ms |
12112 KB |
Output is correct |
45 |
Correct |
92 ms |
17232 KB |
Output is correct |
46 |
Correct |
60 ms |
17748 KB |
Output is correct |
47 |
Correct |
91 ms |
19428 KB |
Output is correct |
48 |
Correct |
174 ms |
30028 KB |
Output is correct |
49 |
Correct |
146 ms |
25680 KB |
Output is correct |
50 |
Correct |
97 ms |
19284 KB |
Output is correct |
51 |
Correct |
92 ms |
19332 KB |
Output is correct |
52 |
Correct |
127 ms |
19604 KB |
Output is correct |
53 |
Correct |
138 ms |
18244 KB |
Output is correct |
54 |
Correct |
120 ms |
19056 KB |
Output is correct |
55 |
Correct |
23 ms |
5724 KB |
Output is correct |
56 |
Correct |
8 ms |
5724 KB |
Output is correct |
57 |
Correct |
44 ms |
12120 KB |
Output is correct |
58 |
Correct |
26 ms |
11984 KB |
Output is correct |
59 |
Execution timed out |
3068 ms |
18508 KB |
Time limit exceeded |
60 |
Halted |
0 ms |
0 KB |
- |