# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1037480 |
2024-07-28T23:55:00 Z |
ArthuroWich |
Race (IOI11_race) |
C++17 |
|
3000 ms |
18512 KB |
#include "race.h"
#include<bits/stdc++.h>
using namespace std;
int n, k, ans = INT_MAX, proc[200005], si[200005];
vector<pair<int, int>> adj[200005];
unordered_map<int, int> occ[2];
void dfs(int i, int p) {
si[i] = 1;
for (auto [j, _] : adj[i]) {
if (proc[j] || j == p) {
continue;
}
dfs(j, i);
si[i] += si[j];
}
}
int centroid(int i, int p, int s) {
for (auto [j, w] : adj[i]) {
if (proc[j] || j == p) {
continue;
}
if (si[j] > s/2) {
return centroid(j, i, s);
}
}
return i;
}
void calc(int i, int p, int d, int path) {
if (path > k) {
return;
}
if (occ[1].find(path) == occ[1].end()) {
occ[1][path] = d;
} else {
occ[1][path] = min(occ[1][path], d);
}
if (k == path) {
ans = min(ans, d);
} else if (occ[0].find(k-path) != occ[0].end()) {
ans = min(ans, d+occ[0][k-path]);
}
for (auto [j, w] : adj[i]) {
if (proc[j] || j == p) {
continue;
}
calc(j, i, d+1, path+w);
}
}
void decompose(int i) {
dfs(i, -1);
if (si[i] == 1) {
return;
}
i = centroid(i, -1, si[i]);
proc[i] = 1;
for (auto [j, w] : adj[i]) {
if (proc[j]) {
continue;
}
calc(j, i, 1, w);
if (occ[0].size() < occ[1].size()) {
occ[0].swap(occ[1]);
}
for (auto c : occ[1]) {
if (occ[0].find(c.first) != occ[0].end()) {
occ[0][c.first] = min(occ[0][c.first], c.second);
} else {
occ[0][c.first] = c.second;
}
}
occ[1].clear();
}
occ[0].clear();
for (auto [j, w] : adj[i]) {
if (proc[j]) {
continue;
}
decompose(j);
}
}
int best_path(int N, int K, int H[][2], int L[]) {
n = N;
k = K;
occ[0].reserve(200000);
occ[1].reserve(200000);
for (int i = 0; i < n-1; i++) {
adj[H[i][0]].push_back({H[i][1], L[i]});
adj[H[i][1]].push_back({H[i][0], L[i]});
}
decompose(1);
if (ans == INT_MAX) {
return -1;
} else {
return ans;
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
11868 KB |
Output is correct |
2 |
Correct |
7 ms |
11896 KB |
Output is correct |
3 |
Correct |
7 ms |
11868 KB |
Output is correct |
4 |
Correct |
8 ms |
11868 KB |
Output is correct |
5 |
Correct |
9 ms |
11984 KB |
Output is correct |
6 |
Correct |
8 ms |
11864 KB |
Output is correct |
7 |
Correct |
8 ms |
11988 KB |
Output is correct |
8 |
Correct |
7 ms |
11868 KB |
Output is correct |
9 |
Correct |
7 ms |
11980 KB |
Output is correct |
10 |
Correct |
7 ms |
11868 KB |
Output is correct |
11 |
Correct |
7 ms |
11868 KB |
Output is correct |
12 |
Correct |
6 ms |
11888 KB |
Output is correct |
13 |
Correct |
7 ms |
11992 KB |
Output is correct |
14 |
Correct |
7 ms |
11988 KB |
Output is correct |
15 |
Correct |
8 ms |
11864 KB |
Output is correct |
16 |
Correct |
7 ms |
11984 KB |
Output is correct |
17 |
Correct |
7 ms |
11868 KB |
Output is correct |
18 |
Correct |
7 ms |
11868 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
11868 KB |
Output is correct |
2 |
Correct |
7 ms |
11896 KB |
Output is correct |
3 |
Correct |
7 ms |
11868 KB |
Output is correct |
4 |
Correct |
8 ms |
11868 KB |
Output is correct |
5 |
Correct |
9 ms |
11984 KB |
Output is correct |
6 |
Correct |
8 ms |
11864 KB |
Output is correct |
7 |
Correct |
8 ms |
11988 KB |
Output is correct |
8 |
Correct |
7 ms |
11868 KB |
Output is correct |
9 |
Correct |
7 ms |
11980 KB |
Output is correct |
10 |
Correct |
7 ms |
11868 KB |
Output is correct |
11 |
Correct |
7 ms |
11868 KB |
Output is correct |
12 |
Correct |
6 ms |
11888 KB |
Output is correct |
13 |
Correct |
7 ms |
11992 KB |
Output is correct |
14 |
Correct |
7 ms |
11988 KB |
Output is correct |
15 |
Correct |
8 ms |
11864 KB |
Output is correct |
16 |
Correct |
7 ms |
11984 KB |
Output is correct |
17 |
Correct |
7 ms |
11868 KB |
Output is correct |
18 |
Correct |
7 ms |
11868 KB |
Output is correct |
19 |
Correct |
3 ms |
11864 KB |
Output is correct |
20 |
Correct |
8 ms |
11864 KB |
Output is correct |
21 |
Correct |
48 ms |
12040 KB |
Output is correct |
22 |
Correct |
49 ms |
11868 KB |
Output is correct |
23 |
Correct |
50 ms |
11868 KB |
Output is correct |
24 |
Correct |
47 ms |
11864 KB |
Output is correct |
25 |
Correct |
49 ms |
12036 KB |
Output is correct |
26 |
Correct |
47 ms |
11864 KB |
Output is correct |
27 |
Correct |
47 ms |
11864 KB |
Output is correct |
28 |
Correct |
46 ms |
11868 KB |
Output is correct |
29 |
Correct |
48 ms |
11868 KB |
Output is correct |
30 |
Correct |
41 ms |
11864 KB |
Output is correct |
31 |
Correct |
43 ms |
11868 KB |
Output is correct |
32 |
Correct |
47 ms |
11868 KB |
Output is correct |
33 |
Correct |
49 ms |
11864 KB |
Output is correct |
34 |
Correct |
49 ms |
11868 KB |
Output is correct |
35 |
Correct |
47 ms |
11868 KB |
Output is correct |
36 |
Correct |
43 ms |
11868 KB |
Output is correct |
37 |
Correct |
44 ms |
12036 KB |
Output is correct |
38 |
Correct |
49 ms |
11864 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
11868 KB |
Output is correct |
2 |
Correct |
7 ms |
11896 KB |
Output is correct |
3 |
Correct |
7 ms |
11868 KB |
Output is correct |
4 |
Correct |
8 ms |
11868 KB |
Output is correct |
5 |
Correct |
9 ms |
11984 KB |
Output is correct |
6 |
Correct |
8 ms |
11864 KB |
Output is correct |
7 |
Correct |
8 ms |
11988 KB |
Output is correct |
8 |
Correct |
7 ms |
11868 KB |
Output is correct |
9 |
Correct |
7 ms |
11980 KB |
Output is correct |
10 |
Correct |
7 ms |
11868 KB |
Output is correct |
11 |
Correct |
7 ms |
11868 KB |
Output is correct |
12 |
Correct |
6 ms |
11888 KB |
Output is correct |
13 |
Correct |
7 ms |
11992 KB |
Output is correct |
14 |
Correct |
7 ms |
11988 KB |
Output is correct |
15 |
Correct |
8 ms |
11864 KB |
Output is correct |
16 |
Correct |
7 ms |
11984 KB |
Output is correct |
17 |
Correct |
7 ms |
11868 KB |
Output is correct |
18 |
Correct |
7 ms |
11868 KB |
Output is correct |
19 |
Execution timed out |
3034 ms |
18512 KB |
Time limit exceeded |
20 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
11868 KB |
Output is correct |
2 |
Correct |
7 ms |
11896 KB |
Output is correct |
3 |
Correct |
7 ms |
11868 KB |
Output is correct |
4 |
Correct |
8 ms |
11868 KB |
Output is correct |
5 |
Correct |
9 ms |
11984 KB |
Output is correct |
6 |
Correct |
8 ms |
11864 KB |
Output is correct |
7 |
Correct |
8 ms |
11988 KB |
Output is correct |
8 |
Correct |
7 ms |
11868 KB |
Output is correct |
9 |
Correct |
7 ms |
11980 KB |
Output is correct |
10 |
Correct |
7 ms |
11868 KB |
Output is correct |
11 |
Correct |
7 ms |
11868 KB |
Output is correct |
12 |
Correct |
6 ms |
11888 KB |
Output is correct |
13 |
Correct |
7 ms |
11992 KB |
Output is correct |
14 |
Correct |
7 ms |
11988 KB |
Output is correct |
15 |
Correct |
8 ms |
11864 KB |
Output is correct |
16 |
Correct |
7 ms |
11984 KB |
Output is correct |
17 |
Correct |
7 ms |
11868 KB |
Output is correct |
18 |
Correct |
7 ms |
11868 KB |
Output is correct |
19 |
Correct |
3 ms |
11864 KB |
Output is correct |
20 |
Correct |
8 ms |
11864 KB |
Output is correct |
21 |
Correct |
48 ms |
12040 KB |
Output is correct |
22 |
Correct |
49 ms |
11868 KB |
Output is correct |
23 |
Correct |
50 ms |
11868 KB |
Output is correct |
24 |
Correct |
47 ms |
11864 KB |
Output is correct |
25 |
Correct |
49 ms |
12036 KB |
Output is correct |
26 |
Correct |
47 ms |
11864 KB |
Output is correct |
27 |
Correct |
47 ms |
11864 KB |
Output is correct |
28 |
Correct |
46 ms |
11868 KB |
Output is correct |
29 |
Correct |
48 ms |
11868 KB |
Output is correct |
30 |
Correct |
41 ms |
11864 KB |
Output is correct |
31 |
Correct |
43 ms |
11868 KB |
Output is correct |
32 |
Correct |
47 ms |
11868 KB |
Output is correct |
33 |
Correct |
49 ms |
11864 KB |
Output is correct |
34 |
Correct |
49 ms |
11868 KB |
Output is correct |
35 |
Correct |
47 ms |
11868 KB |
Output is correct |
36 |
Correct |
43 ms |
11868 KB |
Output is correct |
37 |
Correct |
44 ms |
12036 KB |
Output is correct |
38 |
Correct |
49 ms |
11864 KB |
Output is correct |
39 |
Execution timed out |
3034 ms |
18512 KB |
Time limit exceeded |
40 |
Halted |
0 ms |
0 KB |
- |