# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1104434 |
2024-10-23T18:53:36 Z |
M_W_13 |
Race (IOI11_race) |
C++17 |
|
210 ms |
48628 KB |
#include <bits/stdc++.h>
#include "race.h"
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (n); i++)
int n, k;
const int INF = 1e9;
const int MAXN = 2e5 + 7;
vector<pair<int, int>> graf[MAXN];
int ile_pod[MAXN];
bool czy_centroid[MAXN];
const int MAXK = 1e6 + 2;
int ans = INF;
int jaka[MAXK];
int depth[MAXN];
queue<pair<int, int>> jakie;
queue<int> cofnij;
void dfs(int v, int last, int dl) {
// cout << "v = " << v << " dl = " << dl << '\n';
depth[v] = depth[last] + 1;
ile_pod[v] = 0;
dl = min(dl, k + 1);
if (dl <= k) {
// cout << "XX" << '\n';
ans = min(ans, jaka[k - dl] + depth[v] - 1);
jakie.push({dl, depth[v] - 1});
cofnij.push(dl);
}
for (auto syn: graf[v]) {
if (syn.first == last || czy_centroid[syn.first]) {
continue;
}
dfs(syn.first, v, dl + syn.second);
ile_pod[v] += (ile_pod[syn.first] + 1);
if (depth[v] == 1) {
// cout << "POC" << '\n';
while (!jakie.empty()) {
int a = jakie.front().first;
int b = jakie.front().second;
jaka[a] = min(jaka[a], b);
// cout << "v = " << v << " a = " << a << " b = " << b << '\n';
jakie.pop();
}
// cout << "KON" << '\n';
}
}
}
int find_centroid(int v, int last, int sz) {
int w = v;
for (auto syn: graf[v]) {
if (syn.first == last || czy_centroid[syn.first]) {
continue;
}
// cout << "syn = " << syn.first << " ilepod = " << ile_pod[syn.first] << " size = " << sz << '\n';
if (ile_pod[syn.first] + 1 >= (sz/2)) {
w = find_centroid(syn.first, v, sz);
}
}
return w;
}
void centroid_decomposition(int v, int sz) {
int centre = find_centroid(v, v, sz);
depth[centre] = 0;
// cout << "centre = " << centre << '\n';
czy_centroid[centre] = true;
jaka[0] = 0;
dfs(centre, centre, 0);
while (!cofnij.empty()) {
// cout << "x = " << cofnij.front() << '\n';
jaka[cofnij.front()] = INF;
cofnij.pop();
}
for (auto syn: graf[centre]) {
if (czy_centroid[syn.first]) {
continue;
}
centroid_decomposition(syn.first, ile_pod[syn.first] + 1);
}
}
int best_path(int pom1, int pom2, int H[][2], int L[])
{
n = pom1;
k = pom2;
rep(i, k + 1) {
jaka[i] = INF;
}
rep(i, n - 1) {
int a = H[i][0];
int b = H[i][1];
int waga = L[i];
graf[a].push_back({b, waga});
graf[b].push_back({a, waga});
}
dfs(0, 0, 0);
while (!cofnij.empty()) {
jaka[cofnij.front()] = INF;
cofnij.pop();
}
centroid_decomposition(0, n);
if (ans >= INF) {
return -1;
}
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
12368 KB |
Output is correct |
2 |
Correct |
3 ms |
12368 KB |
Output is correct |
3 |
Correct |
3 ms |
12380 KB |
Output is correct |
4 |
Correct |
3 ms |
12368 KB |
Output is correct |
5 |
Correct |
3 ms |
12404 KB |
Output is correct |
6 |
Correct |
3 ms |
12368 KB |
Output is correct |
7 |
Correct |
3 ms |
12368 KB |
Output is correct |
8 |
Correct |
3 ms |
12368 KB |
Output is correct |
9 |
Correct |
3 ms |
12368 KB |
Output is correct |
10 |
Correct |
3 ms |
12368 KB |
Output is correct |
11 |
Correct |
3 ms |
12368 KB |
Output is correct |
12 |
Correct |
4 ms |
12368 KB |
Output is correct |
13 |
Correct |
3 ms |
12368 KB |
Output is correct |
14 |
Correct |
3 ms |
12404 KB |
Output is correct |
15 |
Correct |
3 ms |
12384 KB |
Output is correct |
16 |
Correct |
4 ms |
12364 KB |
Output is correct |
17 |
Correct |
4 ms |
12368 KB |
Output is correct |
18 |
Correct |
3 ms |
12368 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
12368 KB |
Output is correct |
2 |
Correct |
3 ms |
12368 KB |
Output is correct |
3 |
Correct |
3 ms |
12380 KB |
Output is correct |
4 |
Correct |
3 ms |
12368 KB |
Output is correct |
5 |
Correct |
3 ms |
12404 KB |
Output is correct |
6 |
Correct |
3 ms |
12368 KB |
Output is correct |
7 |
Correct |
3 ms |
12368 KB |
Output is correct |
8 |
Correct |
3 ms |
12368 KB |
Output is correct |
9 |
Correct |
3 ms |
12368 KB |
Output is correct |
10 |
Correct |
3 ms |
12368 KB |
Output is correct |
11 |
Correct |
3 ms |
12368 KB |
Output is correct |
12 |
Correct |
4 ms |
12368 KB |
Output is correct |
13 |
Correct |
3 ms |
12368 KB |
Output is correct |
14 |
Correct |
3 ms |
12404 KB |
Output is correct |
15 |
Correct |
3 ms |
12384 KB |
Output is correct |
16 |
Correct |
4 ms |
12364 KB |
Output is correct |
17 |
Correct |
4 ms |
12368 KB |
Output is correct |
18 |
Correct |
3 ms |
12368 KB |
Output is correct |
19 |
Correct |
3 ms |
12368 KB |
Output is correct |
20 |
Correct |
4 ms |
12476 KB |
Output is correct |
21 |
Correct |
4 ms |
12368 KB |
Output is correct |
22 |
Correct |
4 ms |
14416 KB |
Output is correct |
23 |
Correct |
4 ms |
14416 KB |
Output is correct |
24 |
Correct |
5 ms |
14416 KB |
Output is correct |
25 |
Correct |
3 ms |
14460 KB |
Output is correct |
26 |
Correct |
4 ms |
12536 KB |
Output is correct |
27 |
Correct |
4 ms |
14416 KB |
Output is correct |
28 |
Correct |
4 ms |
12368 KB |
Output is correct |
29 |
Correct |
4 ms |
12424 KB |
Output is correct |
30 |
Correct |
4 ms |
12368 KB |
Output is correct |
31 |
Correct |
4 ms |
14416 KB |
Output is correct |
32 |
Correct |
4 ms |
14428 KB |
Output is correct |
33 |
Correct |
4 ms |
14416 KB |
Output is correct |
34 |
Correct |
4 ms |
14416 KB |
Output is correct |
35 |
Correct |
4 ms |
14416 KB |
Output is correct |
36 |
Correct |
4 ms |
14416 KB |
Output is correct |
37 |
Correct |
4 ms |
14416 KB |
Output is correct |
38 |
Correct |
4 ms |
14416 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
12368 KB |
Output is correct |
2 |
Correct |
3 ms |
12368 KB |
Output is correct |
3 |
Correct |
3 ms |
12380 KB |
Output is correct |
4 |
Correct |
3 ms |
12368 KB |
Output is correct |
5 |
Correct |
3 ms |
12404 KB |
Output is correct |
6 |
Correct |
3 ms |
12368 KB |
Output is correct |
7 |
Correct |
3 ms |
12368 KB |
Output is correct |
8 |
Correct |
3 ms |
12368 KB |
Output is correct |
9 |
Correct |
3 ms |
12368 KB |
Output is correct |
10 |
Correct |
3 ms |
12368 KB |
Output is correct |
11 |
Correct |
3 ms |
12368 KB |
Output is correct |
12 |
Correct |
4 ms |
12368 KB |
Output is correct |
13 |
Correct |
3 ms |
12368 KB |
Output is correct |
14 |
Correct |
3 ms |
12404 KB |
Output is correct |
15 |
Correct |
3 ms |
12384 KB |
Output is correct |
16 |
Correct |
4 ms |
12364 KB |
Output is correct |
17 |
Correct |
4 ms |
12368 KB |
Output is correct |
18 |
Correct |
3 ms |
12368 KB |
Output is correct |
19 |
Correct |
64 ms |
19528 KB |
Output is correct |
20 |
Correct |
65 ms |
19684 KB |
Output is correct |
21 |
Correct |
70 ms |
19724 KB |
Output is correct |
22 |
Correct |
66 ms |
20040 KB |
Output is correct |
23 |
Correct |
49 ms |
19988 KB |
Output is correct |
24 |
Correct |
41 ms |
19980 KB |
Output is correct |
25 |
Correct |
85 ms |
24648 KB |
Output is correct |
26 |
Correct |
66 ms |
30816 KB |
Output is correct |
27 |
Correct |
97 ms |
24968 KB |
Output is correct |
28 |
Correct |
200 ms |
45576 KB |
Output is correct |
29 |
Correct |
195 ms |
44104 KB |
Output is correct |
30 |
Correct |
104 ms |
25100 KB |
Output is correct |
31 |
Correct |
108 ms |
24968 KB |
Output is correct |
32 |
Correct |
130 ms |
25160 KB |
Output is correct |
33 |
Correct |
126 ms |
23628 KB |
Output is correct |
34 |
Correct |
121 ms |
24904 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
12368 KB |
Output is correct |
2 |
Correct |
3 ms |
12368 KB |
Output is correct |
3 |
Correct |
3 ms |
12380 KB |
Output is correct |
4 |
Correct |
3 ms |
12368 KB |
Output is correct |
5 |
Correct |
3 ms |
12404 KB |
Output is correct |
6 |
Correct |
3 ms |
12368 KB |
Output is correct |
7 |
Correct |
3 ms |
12368 KB |
Output is correct |
8 |
Correct |
3 ms |
12368 KB |
Output is correct |
9 |
Correct |
3 ms |
12368 KB |
Output is correct |
10 |
Correct |
3 ms |
12368 KB |
Output is correct |
11 |
Correct |
3 ms |
12368 KB |
Output is correct |
12 |
Correct |
4 ms |
12368 KB |
Output is correct |
13 |
Correct |
3 ms |
12368 KB |
Output is correct |
14 |
Correct |
3 ms |
12404 KB |
Output is correct |
15 |
Correct |
3 ms |
12384 KB |
Output is correct |
16 |
Correct |
4 ms |
12364 KB |
Output is correct |
17 |
Correct |
4 ms |
12368 KB |
Output is correct |
18 |
Correct |
3 ms |
12368 KB |
Output is correct |
19 |
Correct |
3 ms |
12368 KB |
Output is correct |
20 |
Correct |
4 ms |
12476 KB |
Output is correct |
21 |
Correct |
4 ms |
12368 KB |
Output is correct |
22 |
Correct |
4 ms |
14416 KB |
Output is correct |
23 |
Correct |
4 ms |
14416 KB |
Output is correct |
24 |
Correct |
5 ms |
14416 KB |
Output is correct |
25 |
Correct |
3 ms |
14460 KB |
Output is correct |
26 |
Correct |
4 ms |
12536 KB |
Output is correct |
27 |
Correct |
4 ms |
14416 KB |
Output is correct |
28 |
Correct |
4 ms |
12368 KB |
Output is correct |
29 |
Correct |
4 ms |
12424 KB |
Output is correct |
30 |
Correct |
4 ms |
12368 KB |
Output is correct |
31 |
Correct |
4 ms |
14416 KB |
Output is correct |
32 |
Correct |
4 ms |
14428 KB |
Output is correct |
33 |
Correct |
4 ms |
14416 KB |
Output is correct |
34 |
Correct |
4 ms |
14416 KB |
Output is correct |
35 |
Correct |
4 ms |
14416 KB |
Output is correct |
36 |
Correct |
4 ms |
14416 KB |
Output is correct |
37 |
Correct |
4 ms |
14416 KB |
Output is correct |
38 |
Correct |
4 ms |
14416 KB |
Output is correct |
39 |
Correct |
64 ms |
19528 KB |
Output is correct |
40 |
Correct |
65 ms |
19684 KB |
Output is correct |
41 |
Correct |
70 ms |
19724 KB |
Output is correct |
42 |
Correct |
66 ms |
20040 KB |
Output is correct |
43 |
Correct |
49 ms |
19988 KB |
Output is correct |
44 |
Correct |
41 ms |
19980 KB |
Output is correct |
45 |
Correct |
85 ms |
24648 KB |
Output is correct |
46 |
Correct |
66 ms |
30816 KB |
Output is correct |
47 |
Correct |
97 ms |
24968 KB |
Output is correct |
48 |
Correct |
200 ms |
45576 KB |
Output is correct |
49 |
Correct |
195 ms |
44104 KB |
Output is correct |
50 |
Correct |
104 ms |
25100 KB |
Output is correct |
51 |
Correct |
108 ms |
24968 KB |
Output is correct |
52 |
Correct |
130 ms |
25160 KB |
Output is correct |
53 |
Correct |
126 ms |
23628 KB |
Output is correct |
54 |
Correct |
121 ms |
24904 KB |
Output is correct |
55 |
Correct |
7 ms |
12880 KB |
Output is correct |
56 |
Correct |
9 ms |
12880 KB |
Output is correct |
57 |
Correct |
44 ms |
21088 KB |
Output is correct |
58 |
Correct |
29 ms |
20312 KB |
Output is correct |
59 |
Correct |
63 ms |
31048 KB |
Output is correct |
60 |
Correct |
200 ms |
48628 KB |
Output is correct |
61 |
Correct |
109 ms |
25224 KB |
Output is correct |
62 |
Correct |
111 ms |
27976 KB |
Output is correct |
63 |
Correct |
137 ms |
29512 KB |
Output is correct |
64 |
Correct |
200 ms |
29720 KB |
Output is correct |
65 |
Correct |
128 ms |
25928 KB |
Output is correct |
66 |
Correct |
210 ms |
42580 KB |
Output is correct |
67 |
Correct |
70 ms |
30856 KB |
Output is correct |
68 |
Correct |
137 ms |
29000 KB |
Output is correct |
69 |
Correct |
112 ms |
28560 KB |
Output is correct |
70 |
Correct |
103 ms |
27464 KB |
Output is correct |