# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1113005 |
2024-11-15T11:25:36 Z |
akzytr |
Race (IOI11_race) |
C++17 |
|
3000 ms |
108016 KB |
#include "race.h"
#include <bits/stdc++.h>
#define ve vector
#define pb push_back
#define ar array
#define ll long long
using namespace std;
const int MAXN = 3e5;
set<int> adj[MAXN];
map<ar<int, 2>, int> w;
int K;
int ANS = 1e9;
int sub[MAXN];
int processed[MAXN];
void find_size(int x, int p) {
sub[x] = 1;
for(int i : adj[x]) {
if(i != p && !processed[i]) {
find_size(i, x);
sub[x] += sub[i];
}
}
}
int find_centroid(int x, int p, int n) {
for(int i : adj[x]) {
if(sub[i] > n / 2 && i != p) {
return find_centroid(i, x, n);
}
}
return x;
}
void dfs(int x, int p, map<int, int> &vis, map<int, int> &mi_edge, int we, int num_edge, bool upd) {
if(upd) {
if(vis[we]) {
mi_edge[we] = min(mi_edge[we], num_edge);
} else {
vis[we] = 1;
mi_edge[we] = num_edge;
}
} else {
if(vis[K - we]) {
ANS = min(ANS, num_edge + mi_edge[K - we]);
}
}
for(int i : adj[x]) {
if(i != p && we + w[{i, x}] <= K && !processed[i]) {
dfs(i, x, vis, mi_edge, we + w[{i, x}], num_edge + 1, upd);
}
}
}
void process_centroid(int x) {
map<int, int> vis;
map<int, int> mi_edge;
mi_edge[0] = 0;
vis[0] = 1;
for(int i : adj[x]) {
dfs(i, x, vis, mi_edge, w[{i, x}], 1, false);
dfs(i, x, vis, mi_edge, w[{i, x}], 1, true);
}
processed[x] = 1;
}
void decompo(int x) {
find_size(x, -1);
int centroid = find_centroid(x, -1, sub[x]);
process_centroid(centroid);
for(int i : adj[centroid]) {
adj[i].erase(centroid);
}
for(int i : adj[centroid]) {
decompo(i);
}
}
int best_path(int N, int Ked, int H[][2], int L[]) {
fill(processed, processed + MAXN, 0);
for(int i = 0; i < N - 1; i++) {
int a, b;
a = H[i][0];
b = H[i][1];
adj[a].insert(b);
adj[b].insert(a);
w[{a, b}] = L[i];
w[{b, a}] = L[i];
}
K = Ked;
decompo(0);
if(ANS != 1e9) {
return ANS;
}
return -1;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
20560 KB |
Output is correct |
2 |
Correct |
4 ms |
18512 KB |
Output is correct |
3 |
Correct |
5 ms |
16720 KB |
Output is correct |
4 |
Correct |
6 ms |
16720 KB |
Output is correct |
5 |
Correct |
5 ms |
16848 KB |
Output is correct |
6 |
Correct |
6 ms |
16924 KB |
Output is correct |
7 |
Correct |
6 ms |
16720 KB |
Output is correct |
8 |
Correct |
6 ms |
16720 KB |
Output is correct |
9 |
Correct |
7 ms |
16936 KB |
Output is correct |
10 |
Correct |
7 ms |
16892 KB |
Output is correct |
11 |
Correct |
9 ms |
16720 KB |
Output is correct |
12 |
Correct |
7 ms |
16720 KB |
Output is correct |
13 |
Correct |
6 ms |
16720 KB |
Output is correct |
14 |
Correct |
5 ms |
20560 KB |
Output is correct |
15 |
Correct |
4 ms |
20560 KB |
Output is correct |
16 |
Correct |
4 ms |
18512 KB |
Output is correct |
17 |
Correct |
5 ms |
20560 KB |
Output is correct |
18 |
Correct |
5 ms |
16720 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
20560 KB |
Output is correct |
2 |
Correct |
4 ms |
18512 KB |
Output is correct |
3 |
Correct |
5 ms |
16720 KB |
Output is correct |
4 |
Correct |
6 ms |
16720 KB |
Output is correct |
5 |
Correct |
5 ms |
16848 KB |
Output is correct |
6 |
Correct |
6 ms |
16924 KB |
Output is correct |
7 |
Correct |
6 ms |
16720 KB |
Output is correct |
8 |
Correct |
6 ms |
16720 KB |
Output is correct |
9 |
Correct |
7 ms |
16936 KB |
Output is correct |
10 |
Correct |
7 ms |
16892 KB |
Output is correct |
11 |
Correct |
9 ms |
16720 KB |
Output is correct |
12 |
Correct |
7 ms |
16720 KB |
Output is correct |
13 |
Correct |
6 ms |
16720 KB |
Output is correct |
14 |
Correct |
5 ms |
20560 KB |
Output is correct |
15 |
Correct |
4 ms |
20560 KB |
Output is correct |
16 |
Correct |
4 ms |
18512 KB |
Output is correct |
17 |
Correct |
5 ms |
20560 KB |
Output is correct |
18 |
Correct |
5 ms |
16720 KB |
Output is correct |
19 |
Correct |
5 ms |
16720 KB |
Output is correct |
20 |
Correct |
4 ms |
16720 KB |
Output is correct |
21 |
Correct |
7 ms |
18768 KB |
Output is correct |
22 |
Correct |
5 ms |
16976 KB |
Output is correct |
23 |
Correct |
5 ms |
18512 KB |
Output is correct |
24 |
Correct |
7 ms |
16976 KB |
Output is correct |
25 |
Correct |
9 ms |
17248 KB |
Output is correct |
26 |
Correct |
7 ms |
16976 KB |
Output is correct |
27 |
Correct |
5 ms |
16976 KB |
Output is correct |
28 |
Correct |
8 ms |
18768 KB |
Output is correct |
29 |
Correct |
7 ms |
17232 KB |
Output is correct |
30 |
Correct |
9 ms |
17400 KB |
Output is correct |
31 |
Correct |
9 ms |
17260 KB |
Output is correct |
32 |
Correct |
9 ms |
17232 KB |
Output is correct |
33 |
Correct |
11 ms |
17368 KB |
Output is correct |
34 |
Correct |
7 ms |
20560 KB |
Output is correct |
35 |
Correct |
9 ms |
16976 KB |
Output is correct |
36 |
Correct |
11 ms |
16976 KB |
Output is correct |
37 |
Correct |
8 ms |
18740 KB |
Output is correct |
38 |
Correct |
12 ms |
17400 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
20560 KB |
Output is correct |
2 |
Correct |
4 ms |
18512 KB |
Output is correct |
3 |
Correct |
5 ms |
16720 KB |
Output is correct |
4 |
Correct |
6 ms |
16720 KB |
Output is correct |
5 |
Correct |
5 ms |
16848 KB |
Output is correct |
6 |
Correct |
6 ms |
16924 KB |
Output is correct |
7 |
Correct |
6 ms |
16720 KB |
Output is correct |
8 |
Correct |
6 ms |
16720 KB |
Output is correct |
9 |
Correct |
7 ms |
16936 KB |
Output is correct |
10 |
Correct |
7 ms |
16892 KB |
Output is correct |
11 |
Correct |
9 ms |
16720 KB |
Output is correct |
12 |
Correct |
7 ms |
16720 KB |
Output is correct |
13 |
Correct |
6 ms |
16720 KB |
Output is correct |
14 |
Correct |
5 ms |
20560 KB |
Output is correct |
15 |
Correct |
4 ms |
20560 KB |
Output is correct |
16 |
Correct |
4 ms |
18512 KB |
Output is correct |
17 |
Correct |
5 ms |
20560 KB |
Output is correct |
18 |
Correct |
5 ms |
16720 KB |
Output is correct |
19 |
Correct |
819 ms |
41288 KB |
Output is correct |
20 |
Correct |
835 ms |
39912 KB |
Output is correct |
21 |
Correct |
992 ms |
46152 KB |
Output is correct |
22 |
Correct |
1057 ms |
41112 KB |
Output is correct |
23 |
Correct |
348 ms |
41412 KB |
Output is correct |
24 |
Correct |
348 ms |
42944 KB |
Output is correct |
25 |
Correct |
844 ms |
45392 KB |
Output is correct |
26 |
Correct |
611 ms |
49160 KB |
Output is correct |
27 |
Correct |
573 ms |
65164 KB |
Output is correct |
28 |
Correct |
729 ms |
81724 KB |
Output is correct |
29 |
Correct |
812 ms |
80200 KB |
Output is correct |
30 |
Correct |
666 ms |
65740 KB |
Output is correct |
31 |
Correct |
653 ms |
67124 KB |
Output is correct |
32 |
Correct |
980 ms |
65608 KB |
Output is correct |
33 |
Correct |
1483 ms |
65548 KB |
Output is correct |
34 |
Correct |
679 ms |
66376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
20560 KB |
Output is correct |
2 |
Correct |
4 ms |
18512 KB |
Output is correct |
3 |
Correct |
5 ms |
16720 KB |
Output is correct |
4 |
Correct |
6 ms |
16720 KB |
Output is correct |
5 |
Correct |
5 ms |
16848 KB |
Output is correct |
6 |
Correct |
6 ms |
16924 KB |
Output is correct |
7 |
Correct |
6 ms |
16720 KB |
Output is correct |
8 |
Correct |
6 ms |
16720 KB |
Output is correct |
9 |
Correct |
7 ms |
16936 KB |
Output is correct |
10 |
Correct |
7 ms |
16892 KB |
Output is correct |
11 |
Correct |
9 ms |
16720 KB |
Output is correct |
12 |
Correct |
7 ms |
16720 KB |
Output is correct |
13 |
Correct |
6 ms |
16720 KB |
Output is correct |
14 |
Correct |
5 ms |
20560 KB |
Output is correct |
15 |
Correct |
4 ms |
20560 KB |
Output is correct |
16 |
Correct |
4 ms |
18512 KB |
Output is correct |
17 |
Correct |
5 ms |
20560 KB |
Output is correct |
18 |
Correct |
5 ms |
16720 KB |
Output is correct |
19 |
Correct |
5 ms |
16720 KB |
Output is correct |
20 |
Correct |
4 ms |
16720 KB |
Output is correct |
21 |
Correct |
7 ms |
18768 KB |
Output is correct |
22 |
Correct |
5 ms |
16976 KB |
Output is correct |
23 |
Correct |
5 ms |
18512 KB |
Output is correct |
24 |
Correct |
7 ms |
16976 KB |
Output is correct |
25 |
Correct |
9 ms |
17248 KB |
Output is correct |
26 |
Correct |
7 ms |
16976 KB |
Output is correct |
27 |
Correct |
5 ms |
16976 KB |
Output is correct |
28 |
Correct |
8 ms |
18768 KB |
Output is correct |
29 |
Correct |
7 ms |
17232 KB |
Output is correct |
30 |
Correct |
9 ms |
17400 KB |
Output is correct |
31 |
Correct |
9 ms |
17260 KB |
Output is correct |
32 |
Correct |
9 ms |
17232 KB |
Output is correct |
33 |
Correct |
11 ms |
17368 KB |
Output is correct |
34 |
Correct |
7 ms |
20560 KB |
Output is correct |
35 |
Correct |
9 ms |
16976 KB |
Output is correct |
36 |
Correct |
11 ms |
16976 KB |
Output is correct |
37 |
Correct |
8 ms |
18740 KB |
Output is correct |
38 |
Correct |
12 ms |
17400 KB |
Output is correct |
39 |
Correct |
819 ms |
41288 KB |
Output is correct |
40 |
Correct |
835 ms |
39912 KB |
Output is correct |
41 |
Correct |
992 ms |
46152 KB |
Output is correct |
42 |
Correct |
1057 ms |
41112 KB |
Output is correct |
43 |
Correct |
348 ms |
41412 KB |
Output is correct |
44 |
Correct |
348 ms |
42944 KB |
Output is correct |
45 |
Correct |
844 ms |
45392 KB |
Output is correct |
46 |
Correct |
611 ms |
49160 KB |
Output is correct |
47 |
Correct |
573 ms |
65164 KB |
Output is correct |
48 |
Correct |
729 ms |
81724 KB |
Output is correct |
49 |
Correct |
812 ms |
80200 KB |
Output is correct |
50 |
Correct |
666 ms |
65740 KB |
Output is correct |
51 |
Correct |
653 ms |
67124 KB |
Output is correct |
52 |
Correct |
980 ms |
65608 KB |
Output is correct |
53 |
Correct |
1483 ms |
65548 KB |
Output is correct |
54 |
Correct |
679 ms |
66376 KB |
Output is correct |
55 |
Correct |
66 ms |
21236 KB |
Output is correct |
56 |
Correct |
53 ms |
19164 KB |
Output is correct |
57 |
Correct |
742 ms |
41288 KB |
Output is correct |
58 |
Correct |
139 ms |
41032 KB |
Output is correct |
59 |
Correct |
1121 ms |
59324 KB |
Output is correct |
60 |
Execution timed out |
3059 ms |
108016 KB |
Time limit exceeded |
61 |
Halted |
0 ms |
0 KB |
- |