# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
821838 |
2023-08-11T18:43:16 Z |
nemethm |
Race (IOI11_race) |
C++17 |
|
249 ms |
121760 KB |
#include "race.h"
#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
vector<pair<int,ll>> g[200100];
int level[1001], dist[1001];
int k, ans = -1;
int minl[200100][110] = {0};
void dfs(int node, int prev = -1){
if(dist[node] == k){
ans = ans == -1 ? level[node] : min(ans, level[node]);
}
for(auto i : g[node]){
if(i.first != prev){
level[i.first] = level[node] + 1;
dist[i.first] = dist[node] + i.second;
dfs(i.first, node);
}
}
}
void dfs2(int node, int prev = -1){
for(auto i : g[node]){
if(i.first != prev){
dfs2(i.first, node);
vector<int> temp(k + 1);
if(i.second <= k)
temp[i.second] = 1;
for(int j = 1; j + i.second <= k; ++j){
if(minl[i.first][j] == 0) continue;
temp[j + i.second] = minl[i.first][j] + 1;
}
for(int j = 1; j < k; ++j){
if(temp[j] > 0 && minl[node][k - j] > 0){
if(ans == -1){
ans = temp[j] + minl[node][k - j];
}
else{
ans = min(ans, temp[j] + minl[node][k - j]);
}
}
}
if(temp[k] > 0){
ans = ans == -1 ? temp[k] : min(ans, temp[k]);
}
if(i.second <= k)
minl[node][i.second] = 1;
for(int j = 1; j + i.second <= k; ++j){
if(minl[i.first][j] == 0) continue;
if(minl[node][j + i.second] == 0){
minl[node][j + i.second] = minl[i.first][j] + 1;
}
else{
minl[node][j + i.second] = min(minl[i.first][j] + 1, minl[node][j + i.second]);
}
}
}
}
}
int best_path(int N, int K, int H[][2], int L[])
{
k = K;
for(int i = 0; i < N - 1; ++i){
g[H[i][0]].push_back({H[i][1], L[i]});
g[H[i][1]].push_back({H[i][0], L[i]});
}
if(N <= 1000){
for(int i = 0; i < N; ++i){
fill(level, level + N, 0);
fill(dist, dist + N, 0);
dfs(i);
}
}
else{
dfs2(0);
}
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4948 KB |
Output is correct |
2 |
Correct |
3 ms |
5048 KB |
Output is correct |
3 |
Correct |
3 ms |
4948 KB |
Output is correct |
4 |
Correct |
2 ms |
4948 KB |
Output is correct |
5 |
Correct |
3 ms |
5016 KB |
Output is correct |
6 |
Correct |
3 ms |
5008 KB |
Output is correct |
7 |
Correct |
2 ms |
4948 KB |
Output is correct |
8 |
Correct |
2 ms |
4948 KB |
Output is correct |
9 |
Correct |
3 ms |
4956 KB |
Output is correct |
10 |
Correct |
3 ms |
4948 KB |
Output is correct |
11 |
Correct |
3 ms |
4948 KB |
Output is correct |
12 |
Correct |
2 ms |
4948 KB |
Output is correct |
13 |
Correct |
2 ms |
4948 KB |
Output is correct |
14 |
Correct |
2 ms |
5008 KB |
Output is correct |
15 |
Correct |
2 ms |
4948 KB |
Output is correct |
16 |
Correct |
2 ms |
4948 KB |
Output is correct |
17 |
Correct |
3 ms |
4948 KB |
Output is correct |
18 |
Correct |
2 ms |
4940 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4948 KB |
Output is correct |
2 |
Correct |
3 ms |
5048 KB |
Output is correct |
3 |
Correct |
3 ms |
4948 KB |
Output is correct |
4 |
Correct |
2 ms |
4948 KB |
Output is correct |
5 |
Correct |
3 ms |
5016 KB |
Output is correct |
6 |
Correct |
3 ms |
5008 KB |
Output is correct |
7 |
Correct |
2 ms |
4948 KB |
Output is correct |
8 |
Correct |
2 ms |
4948 KB |
Output is correct |
9 |
Correct |
3 ms |
4956 KB |
Output is correct |
10 |
Correct |
3 ms |
4948 KB |
Output is correct |
11 |
Correct |
3 ms |
4948 KB |
Output is correct |
12 |
Correct |
2 ms |
4948 KB |
Output is correct |
13 |
Correct |
2 ms |
4948 KB |
Output is correct |
14 |
Correct |
2 ms |
5008 KB |
Output is correct |
15 |
Correct |
2 ms |
4948 KB |
Output is correct |
16 |
Correct |
2 ms |
4948 KB |
Output is correct |
17 |
Correct |
3 ms |
4948 KB |
Output is correct |
18 |
Correct |
2 ms |
4940 KB |
Output is correct |
19 |
Correct |
2 ms |
5012 KB |
Output is correct |
20 |
Correct |
2 ms |
4948 KB |
Output is correct |
21 |
Correct |
9 ms |
5076 KB |
Output is correct |
22 |
Correct |
12 ms |
5116 KB |
Output is correct |
23 |
Correct |
10 ms |
5076 KB |
Output is correct |
24 |
Correct |
9 ms |
5076 KB |
Output is correct |
25 |
Correct |
9 ms |
5076 KB |
Output is correct |
26 |
Correct |
10 ms |
5012 KB |
Output is correct |
27 |
Correct |
9 ms |
5076 KB |
Output is correct |
28 |
Correct |
9 ms |
5020 KB |
Output is correct |
29 |
Correct |
9 ms |
5076 KB |
Output is correct |
30 |
Correct |
9 ms |
5108 KB |
Output is correct |
31 |
Correct |
10 ms |
5024 KB |
Output is correct |
32 |
Correct |
9 ms |
5076 KB |
Output is correct |
33 |
Correct |
10 ms |
5076 KB |
Output is correct |
34 |
Correct |
10 ms |
5120 KB |
Output is correct |
35 |
Correct |
9 ms |
5076 KB |
Output is correct |
36 |
Correct |
8 ms |
5016 KB |
Output is correct |
37 |
Correct |
9 ms |
5116 KB |
Output is correct |
38 |
Correct |
10 ms |
5076 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4948 KB |
Output is correct |
2 |
Correct |
3 ms |
5048 KB |
Output is correct |
3 |
Correct |
3 ms |
4948 KB |
Output is correct |
4 |
Correct |
2 ms |
4948 KB |
Output is correct |
5 |
Correct |
3 ms |
5016 KB |
Output is correct |
6 |
Correct |
3 ms |
5008 KB |
Output is correct |
7 |
Correct |
2 ms |
4948 KB |
Output is correct |
8 |
Correct |
2 ms |
4948 KB |
Output is correct |
9 |
Correct |
3 ms |
4956 KB |
Output is correct |
10 |
Correct |
3 ms |
4948 KB |
Output is correct |
11 |
Correct |
3 ms |
4948 KB |
Output is correct |
12 |
Correct |
2 ms |
4948 KB |
Output is correct |
13 |
Correct |
2 ms |
4948 KB |
Output is correct |
14 |
Correct |
2 ms |
5008 KB |
Output is correct |
15 |
Correct |
2 ms |
4948 KB |
Output is correct |
16 |
Correct |
2 ms |
4948 KB |
Output is correct |
17 |
Correct |
3 ms |
4948 KB |
Output is correct |
18 |
Correct |
2 ms |
4940 KB |
Output is correct |
19 |
Correct |
144 ms |
52336 KB |
Output is correct |
20 |
Correct |
120 ms |
52352 KB |
Output is correct |
21 |
Correct |
115 ms |
51740 KB |
Output is correct |
22 |
Correct |
113 ms |
54476 KB |
Output is correct |
23 |
Correct |
123 ms |
54948 KB |
Output is correct |
24 |
Correct |
80 ms |
44944 KB |
Output is correct |
25 |
Correct |
108 ms |
59124 KB |
Output is correct |
26 |
Correct |
82 ms |
63536 KB |
Output is correct |
27 |
Correct |
191 ms |
62324 KB |
Output is correct |
28 |
Correct |
217 ms |
121760 KB |
Output is correct |
29 |
Correct |
205 ms |
120208 KB |
Output is correct |
30 |
Correct |
181 ms |
65060 KB |
Output is correct |
31 |
Correct |
187 ms |
64984 KB |
Output is correct |
32 |
Correct |
242 ms |
106460 KB |
Output is correct |
33 |
Correct |
249 ms |
105528 KB |
Output is correct |
34 |
Correct |
87 ms |
21280 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4948 KB |
Output is correct |
2 |
Correct |
3 ms |
5048 KB |
Output is correct |
3 |
Correct |
3 ms |
4948 KB |
Output is correct |
4 |
Correct |
2 ms |
4948 KB |
Output is correct |
5 |
Correct |
3 ms |
5016 KB |
Output is correct |
6 |
Correct |
3 ms |
5008 KB |
Output is correct |
7 |
Correct |
2 ms |
4948 KB |
Output is correct |
8 |
Correct |
2 ms |
4948 KB |
Output is correct |
9 |
Correct |
3 ms |
4956 KB |
Output is correct |
10 |
Correct |
3 ms |
4948 KB |
Output is correct |
11 |
Correct |
3 ms |
4948 KB |
Output is correct |
12 |
Correct |
2 ms |
4948 KB |
Output is correct |
13 |
Correct |
2 ms |
4948 KB |
Output is correct |
14 |
Correct |
2 ms |
5008 KB |
Output is correct |
15 |
Correct |
2 ms |
4948 KB |
Output is correct |
16 |
Correct |
2 ms |
4948 KB |
Output is correct |
17 |
Correct |
3 ms |
4948 KB |
Output is correct |
18 |
Correct |
2 ms |
4940 KB |
Output is correct |
19 |
Correct |
2 ms |
5012 KB |
Output is correct |
20 |
Correct |
2 ms |
4948 KB |
Output is correct |
21 |
Correct |
9 ms |
5076 KB |
Output is correct |
22 |
Correct |
12 ms |
5116 KB |
Output is correct |
23 |
Correct |
10 ms |
5076 KB |
Output is correct |
24 |
Correct |
9 ms |
5076 KB |
Output is correct |
25 |
Correct |
9 ms |
5076 KB |
Output is correct |
26 |
Correct |
10 ms |
5012 KB |
Output is correct |
27 |
Correct |
9 ms |
5076 KB |
Output is correct |
28 |
Correct |
9 ms |
5020 KB |
Output is correct |
29 |
Correct |
9 ms |
5076 KB |
Output is correct |
30 |
Correct |
9 ms |
5108 KB |
Output is correct |
31 |
Correct |
10 ms |
5024 KB |
Output is correct |
32 |
Correct |
9 ms |
5076 KB |
Output is correct |
33 |
Correct |
10 ms |
5076 KB |
Output is correct |
34 |
Correct |
10 ms |
5120 KB |
Output is correct |
35 |
Correct |
9 ms |
5076 KB |
Output is correct |
36 |
Correct |
8 ms |
5016 KB |
Output is correct |
37 |
Correct |
9 ms |
5116 KB |
Output is correct |
38 |
Correct |
10 ms |
5076 KB |
Output is correct |
39 |
Correct |
144 ms |
52336 KB |
Output is correct |
40 |
Correct |
120 ms |
52352 KB |
Output is correct |
41 |
Correct |
115 ms |
51740 KB |
Output is correct |
42 |
Correct |
113 ms |
54476 KB |
Output is correct |
43 |
Correct |
123 ms |
54948 KB |
Output is correct |
44 |
Correct |
80 ms |
44944 KB |
Output is correct |
45 |
Correct |
108 ms |
59124 KB |
Output is correct |
46 |
Correct |
82 ms |
63536 KB |
Output is correct |
47 |
Correct |
191 ms |
62324 KB |
Output is correct |
48 |
Correct |
217 ms |
121760 KB |
Output is correct |
49 |
Correct |
205 ms |
120208 KB |
Output is correct |
50 |
Correct |
181 ms |
65060 KB |
Output is correct |
51 |
Correct |
187 ms |
64984 KB |
Output is correct |
52 |
Correct |
242 ms |
106460 KB |
Output is correct |
53 |
Correct |
249 ms |
105528 KB |
Output is correct |
54 |
Correct |
87 ms |
21280 KB |
Output is correct |
55 |
Incorrect |
146 ms |
10008 KB |
Output isn't correct |
56 |
Halted |
0 ms |
0 KB |
- |