# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
445260 |
2021-07-17T07:55:20 Z |
prvocislo |
Race (IOI11_race) |
C++17 |
|
1029 ms |
41840 KB |
#include "race.h"
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 5;
int n, k, ans = maxn;
vector<bool> alive(maxn, true);
vector<int> siz(maxn, 0);
vector<vector<pair<int, int> > > g(maxn);
void dfs_size(int u, int p = -1)
{
siz[u] = 1;
for (pair<int, int> i : g[u])
{
if (!alive[i.first] || i.first == p) continue;
dfs_size(i.first, u);
siz[u] += siz[i.first];
}
}
int dfs_centroid(int u, int s, int p = -1)
{
for (const pair<int, int> &i : g[u])
{
if (!alive[i.first] || i.first == p) continue;
if (siz[i.first] > s/2) return dfs_centroid(i.first, s, u);
}
return u;
}
void dfs_dist(int u, vector<pair<int, int> > &v, int depth = 0, int dist = 0, int p = -1)
{
if (dist == k) return (void)(ans = min(ans, depth));
if (dist > k) return;
v.push_back({dist, depth});
for (pair<int, int> i : g[u])
{
if (!alive[i.first] || i.first == p) continue;
dfs_dist(i.first, v, depth+1, dist+i.second, u);
}
}
void centroid_decomp(int r)
{
dfs_size(r);
int u = dfs_centroid(r, siz[r]);
map<int, int> m;
alive[u] = false;
for (const pair<int, int> &i : g[u])
{
if (!alive[i.first]) continue;
centroid_decomp(i.first);
vector<pair<int, int> > v;
dfs_dist(i.first, v, 1, i.second, u);
for (const pair<int, int> &j : v)
{
//cout << m.count(k-j.first) << " " << m[k-j.first] << "\n";
if (m.count(k-j.first))
ans = min(ans, j.second+m[k-j.first]);
}
for (const pair<int, int> &j : v)
if (!m.count(j.first))
m[j.first] = j.second;
else
m[j.first] = min(m[j.first], j.second);
//cout << "\n" << u << "\n";
//for (pair<int, int> j : m) cout << j.first << " " << j.second << "\n";
}
alive[u] = true;
}
int best_path(int N, int K, int e[][2], int l[])
{
n = N, k = K;
for (int i = 0; i < n-1; i++)
{
g[e[i][0]].push_back({e[i][1], l[i]});
g[e[i][1]].push_back({e[i][0], l[i]});
}
centroid_decomp(0);
return ans == maxn ? -1 : ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
5836 KB |
Output is correct |
2 |
Correct |
4 ms |
5836 KB |
Output is correct |
3 |
Correct |
4 ms |
5836 KB |
Output is correct |
4 |
Correct |
4 ms |
5708 KB |
Output is correct |
5 |
Correct |
4 ms |
5708 KB |
Output is correct |
6 |
Correct |
4 ms |
5836 KB |
Output is correct |
7 |
Correct |
4 ms |
5836 KB |
Output is correct |
8 |
Correct |
4 ms |
5816 KB |
Output is correct |
9 |
Correct |
4 ms |
5836 KB |
Output is correct |
10 |
Correct |
4 ms |
5960 KB |
Output is correct |
11 |
Correct |
4 ms |
5708 KB |
Output is correct |
12 |
Correct |
4 ms |
5836 KB |
Output is correct |
13 |
Correct |
4 ms |
5836 KB |
Output is correct |
14 |
Correct |
4 ms |
5824 KB |
Output is correct |
15 |
Correct |
5 ms |
5716 KB |
Output is correct |
16 |
Correct |
4 ms |
5756 KB |
Output is correct |
17 |
Correct |
4 ms |
5816 KB |
Output is correct |
18 |
Correct |
4 ms |
5820 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
5836 KB |
Output is correct |
2 |
Correct |
4 ms |
5836 KB |
Output is correct |
3 |
Correct |
4 ms |
5836 KB |
Output is correct |
4 |
Correct |
4 ms |
5708 KB |
Output is correct |
5 |
Correct |
4 ms |
5708 KB |
Output is correct |
6 |
Correct |
4 ms |
5836 KB |
Output is correct |
7 |
Correct |
4 ms |
5836 KB |
Output is correct |
8 |
Correct |
4 ms |
5816 KB |
Output is correct |
9 |
Correct |
4 ms |
5836 KB |
Output is correct |
10 |
Correct |
4 ms |
5960 KB |
Output is correct |
11 |
Correct |
4 ms |
5708 KB |
Output is correct |
12 |
Correct |
4 ms |
5836 KB |
Output is correct |
13 |
Correct |
4 ms |
5836 KB |
Output is correct |
14 |
Correct |
4 ms |
5824 KB |
Output is correct |
15 |
Correct |
5 ms |
5716 KB |
Output is correct |
16 |
Correct |
4 ms |
5756 KB |
Output is correct |
17 |
Correct |
4 ms |
5816 KB |
Output is correct |
18 |
Correct |
4 ms |
5820 KB |
Output is correct |
19 |
Correct |
5 ms |
5820 KB |
Output is correct |
20 |
Correct |
5 ms |
5732 KB |
Output is correct |
21 |
Correct |
6 ms |
5836 KB |
Output is correct |
22 |
Correct |
5 ms |
5836 KB |
Output is correct |
23 |
Correct |
4 ms |
5836 KB |
Output is correct |
24 |
Correct |
5 ms |
5836 KB |
Output is correct |
25 |
Correct |
6 ms |
5836 KB |
Output is correct |
26 |
Correct |
4 ms |
5836 KB |
Output is correct |
27 |
Correct |
5 ms |
5836 KB |
Output is correct |
28 |
Correct |
7 ms |
5836 KB |
Output is correct |
29 |
Correct |
6 ms |
5828 KB |
Output is correct |
30 |
Correct |
6 ms |
5824 KB |
Output is correct |
31 |
Correct |
6 ms |
5836 KB |
Output is correct |
32 |
Correct |
6 ms |
5828 KB |
Output is correct |
33 |
Correct |
6 ms |
5832 KB |
Output is correct |
34 |
Correct |
5 ms |
5836 KB |
Output is correct |
35 |
Correct |
5 ms |
5836 KB |
Output is correct |
36 |
Correct |
6 ms |
5964 KB |
Output is correct |
37 |
Correct |
5 ms |
5836 KB |
Output is correct |
38 |
Correct |
6 ms |
5836 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
5836 KB |
Output is correct |
2 |
Correct |
4 ms |
5836 KB |
Output is correct |
3 |
Correct |
4 ms |
5836 KB |
Output is correct |
4 |
Correct |
4 ms |
5708 KB |
Output is correct |
5 |
Correct |
4 ms |
5708 KB |
Output is correct |
6 |
Correct |
4 ms |
5836 KB |
Output is correct |
7 |
Correct |
4 ms |
5836 KB |
Output is correct |
8 |
Correct |
4 ms |
5816 KB |
Output is correct |
9 |
Correct |
4 ms |
5836 KB |
Output is correct |
10 |
Correct |
4 ms |
5960 KB |
Output is correct |
11 |
Correct |
4 ms |
5708 KB |
Output is correct |
12 |
Correct |
4 ms |
5836 KB |
Output is correct |
13 |
Correct |
4 ms |
5836 KB |
Output is correct |
14 |
Correct |
4 ms |
5824 KB |
Output is correct |
15 |
Correct |
5 ms |
5716 KB |
Output is correct |
16 |
Correct |
4 ms |
5756 KB |
Output is correct |
17 |
Correct |
4 ms |
5816 KB |
Output is correct |
18 |
Correct |
4 ms |
5820 KB |
Output is correct |
19 |
Correct |
223 ms |
11808 KB |
Output is correct |
20 |
Correct |
219 ms |
12100 KB |
Output is correct |
21 |
Correct |
255 ms |
12432 KB |
Output is correct |
22 |
Correct |
258 ms |
12472 KB |
Output is correct |
23 |
Correct |
104 ms |
12276 KB |
Output is correct |
24 |
Correct |
94 ms |
12164 KB |
Output is correct |
25 |
Correct |
172 ms |
15568 KB |
Output is correct |
26 |
Correct |
145 ms |
20232 KB |
Output is correct |
27 |
Correct |
238 ms |
18628 KB |
Output is correct |
28 |
Correct |
323 ms |
33096 KB |
Output is correct |
29 |
Correct |
307 ms |
31892 KB |
Output is correct |
30 |
Correct |
249 ms |
18756 KB |
Output is correct |
31 |
Correct |
231 ms |
18552 KB |
Output is correct |
32 |
Correct |
271 ms |
18676 KB |
Output is correct |
33 |
Correct |
340 ms |
17556 KB |
Output is correct |
34 |
Correct |
226 ms |
18628 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
5836 KB |
Output is correct |
2 |
Correct |
4 ms |
5836 KB |
Output is correct |
3 |
Correct |
4 ms |
5836 KB |
Output is correct |
4 |
Correct |
4 ms |
5708 KB |
Output is correct |
5 |
Correct |
4 ms |
5708 KB |
Output is correct |
6 |
Correct |
4 ms |
5836 KB |
Output is correct |
7 |
Correct |
4 ms |
5836 KB |
Output is correct |
8 |
Correct |
4 ms |
5816 KB |
Output is correct |
9 |
Correct |
4 ms |
5836 KB |
Output is correct |
10 |
Correct |
4 ms |
5960 KB |
Output is correct |
11 |
Correct |
4 ms |
5708 KB |
Output is correct |
12 |
Correct |
4 ms |
5836 KB |
Output is correct |
13 |
Correct |
4 ms |
5836 KB |
Output is correct |
14 |
Correct |
4 ms |
5824 KB |
Output is correct |
15 |
Correct |
5 ms |
5716 KB |
Output is correct |
16 |
Correct |
4 ms |
5756 KB |
Output is correct |
17 |
Correct |
4 ms |
5816 KB |
Output is correct |
18 |
Correct |
4 ms |
5820 KB |
Output is correct |
19 |
Correct |
5 ms |
5820 KB |
Output is correct |
20 |
Correct |
5 ms |
5732 KB |
Output is correct |
21 |
Correct |
6 ms |
5836 KB |
Output is correct |
22 |
Correct |
5 ms |
5836 KB |
Output is correct |
23 |
Correct |
4 ms |
5836 KB |
Output is correct |
24 |
Correct |
5 ms |
5836 KB |
Output is correct |
25 |
Correct |
6 ms |
5836 KB |
Output is correct |
26 |
Correct |
4 ms |
5836 KB |
Output is correct |
27 |
Correct |
5 ms |
5836 KB |
Output is correct |
28 |
Correct |
7 ms |
5836 KB |
Output is correct |
29 |
Correct |
6 ms |
5828 KB |
Output is correct |
30 |
Correct |
6 ms |
5824 KB |
Output is correct |
31 |
Correct |
6 ms |
5836 KB |
Output is correct |
32 |
Correct |
6 ms |
5828 KB |
Output is correct |
33 |
Correct |
6 ms |
5832 KB |
Output is correct |
34 |
Correct |
5 ms |
5836 KB |
Output is correct |
35 |
Correct |
5 ms |
5836 KB |
Output is correct |
36 |
Correct |
6 ms |
5964 KB |
Output is correct |
37 |
Correct |
5 ms |
5836 KB |
Output is correct |
38 |
Correct |
6 ms |
5836 KB |
Output is correct |
39 |
Correct |
223 ms |
11808 KB |
Output is correct |
40 |
Correct |
219 ms |
12100 KB |
Output is correct |
41 |
Correct |
255 ms |
12432 KB |
Output is correct |
42 |
Correct |
258 ms |
12472 KB |
Output is correct |
43 |
Correct |
104 ms |
12276 KB |
Output is correct |
44 |
Correct |
94 ms |
12164 KB |
Output is correct |
45 |
Correct |
172 ms |
15568 KB |
Output is correct |
46 |
Correct |
145 ms |
20232 KB |
Output is correct |
47 |
Correct |
238 ms |
18628 KB |
Output is correct |
48 |
Correct |
323 ms |
33096 KB |
Output is correct |
49 |
Correct |
307 ms |
31892 KB |
Output is correct |
50 |
Correct |
249 ms |
18756 KB |
Output is correct |
51 |
Correct |
231 ms |
18552 KB |
Output is correct |
52 |
Correct |
271 ms |
18676 KB |
Output is correct |
53 |
Correct |
340 ms |
17556 KB |
Output is correct |
54 |
Correct |
226 ms |
18628 KB |
Output is correct |
55 |
Correct |
24 ms |
6564 KB |
Output is correct |
56 |
Correct |
18 ms |
6476 KB |
Output is correct |
57 |
Correct |
175 ms |
12964 KB |
Output is correct |
58 |
Correct |
56 ms |
11844 KB |
Output is correct |
59 |
Correct |
371 ms |
23980 KB |
Output is correct |
60 |
Correct |
1029 ms |
41840 KB |
Output is correct |
61 |
Correct |
308 ms |
19040 KB |
Output is correct |
62 |
Correct |
343 ms |
18824 KB |
Output is correct |
63 |
Correct |
434 ms |
18832 KB |
Output is correct |
64 |
Correct |
978 ms |
25124 KB |
Output is correct |
65 |
Correct |
252 ms |
19400 KB |
Output is correct |
66 |
Correct |
662 ms |
30396 KB |
Output is correct |
67 |
Correct |
154 ms |
19380 KB |
Output is correct |
68 |
Correct |
460 ms |
23136 KB |
Output is correct |
69 |
Correct |
489 ms |
23068 KB |
Output is correct |
70 |
Correct |
455 ms |
22384 KB |
Output is correct |