# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
574161 |
2022-06-08T05:14:13 Z |
AJ00 |
Race (IOI11_race) |
C++14 |
|
3000 ms |
27128 KB |
#include <bits/stdc++.h>
//#include "race.h"
using namespace std;
//#define int long long
//#define int long long
const int MAXN = 200001;
const int LOGN = 20;
vector<vector<pair<int,int>>> adj(MAXN);
int depth[MAXN];
int par[MAXN][LOGN],weight[MAXN][LOGN];
pair<int,int> lca(int x, int y){
int X = x, Y = y;
if (depth[X] < depth[Y]){
swap(x,y);
swap(X,Y);
}
int dh = depth[x]-depth[y];
int totw = 0;
for (int i = LOGN-1; i >= 0; i--){
if (dh&(1<<i)){
totw += weight[x][i];
x = par[x][i];
}
}
if (x == y){
return {totw, depth[X]-depth[Y]};
}
int lvl = 0;
for (int i = LOGN-1; i >= 0; i--){
if (par[x][i] != par[y][i]){
totw += weight[x][i];
totw += weight[y][i];
lvl += (1<<i);
x = par[x][i];
y = par[y][i];
}
}
totw += weight[x][0];
totw += weight[y][0];
lvl += 1;
lvl *= 2;
return {totw,lvl+depth[X]-depth[Y]};
}
void dfs(int x, int h = 0, int p= 0, int w = 0){
depth[x] = h;
par[x][0] = p;
weight[x][0] = w;
for (int i = 1; i < LOGN; i++){
par[x][i] = par[par[x][i-1]][i-1];
weight[x][i] = weight[x][i-1] + weight[par[x][i-1]][i-1];
}
for (auto ch: adj[x]){
int t = ch.first;
int wt = ch.second;
if (t != p){
dfs(t,h+1,x,wt);
}
}
}
int best_path(int N,int K,int H[][2],int L[]){
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]});
}
dfs(0);
int ans = N;
for (int i = 0; i < N; i++){
for (int j = i+1; j < N; j++){
pair<int,int> l = lca(i,j);
if (l.first == K){
// cout << i << " " << j << " " << depth[i] << " " << depth[j] << "\n";
ans = min(ans,l.second);
}
}
}
ans -= (ans == N ? N+1 : 0);
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
5012 KB |
Output is correct |
2 |
Correct |
4 ms |
5020 KB |
Output is correct |
3 |
Correct |
3 ms |
5012 KB |
Output is correct |
4 |
Correct |
3 ms |
5032 KB |
Output is correct |
5 |
Correct |
3 ms |
4980 KB |
Output is correct |
6 |
Correct |
3 ms |
4948 KB |
Output is correct |
7 |
Correct |
3 ms |
5076 KB |
Output is correct |
8 |
Correct |
3 ms |
5016 KB |
Output is correct |
9 |
Correct |
3 ms |
5020 KB |
Output is correct |
10 |
Correct |
4 ms |
5016 KB |
Output is correct |
11 |
Correct |
3 ms |
4948 KB |
Output is correct |
12 |
Correct |
3 ms |
4948 KB |
Output is correct |
13 |
Correct |
3 ms |
5020 KB |
Output is correct |
14 |
Correct |
4 ms |
5016 KB |
Output is correct |
15 |
Correct |
3 ms |
5004 KB |
Output is correct |
16 |
Correct |
5 ms |
5068 KB |
Output is correct |
17 |
Correct |
4 ms |
4948 KB |
Output is correct |
18 |
Correct |
3 ms |
4948 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
5012 KB |
Output is correct |
2 |
Correct |
4 ms |
5020 KB |
Output is correct |
3 |
Correct |
3 ms |
5012 KB |
Output is correct |
4 |
Correct |
3 ms |
5032 KB |
Output is correct |
5 |
Correct |
3 ms |
4980 KB |
Output is correct |
6 |
Correct |
3 ms |
4948 KB |
Output is correct |
7 |
Correct |
3 ms |
5076 KB |
Output is correct |
8 |
Correct |
3 ms |
5016 KB |
Output is correct |
9 |
Correct |
3 ms |
5020 KB |
Output is correct |
10 |
Correct |
4 ms |
5016 KB |
Output is correct |
11 |
Correct |
3 ms |
4948 KB |
Output is correct |
12 |
Correct |
3 ms |
4948 KB |
Output is correct |
13 |
Correct |
3 ms |
5020 KB |
Output is correct |
14 |
Correct |
4 ms |
5016 KB |
Output is correct |
15 |
Correct |
3 ms |
5004 KB |
Output is correct |
16 |
Correct |
5 ms |
5068 KB |
Output is correct |
17 |
Correct |
4 ms |
4948 KB |
Output is correct |
18 |
Correct |
3 ms |
4948 KB |
Output is correct |
19 |
Correct |
3 ms |
4948 KB |
Output is correct |
20 |
Correct |
3 ms |
4948 KB |
Output is correct |
21 |
Correct |
43 ms |
5204 KB |
Output is correct |
22 |
Correct |
46 ms |
5204 KB |
Output is correct |
23 |
Correct |
45 ms |
5264 KB |
Output is correct |
24 |
Correct |
43 ms |
5244 KB |
Output is correct |
25 |
Correct |
46 ms |
5156 KB |
Output is correct |
26 |
Correct |
48 ms |
5244 KB |
Output is correct |
27 |
Correct |
42 ms |
5240 KB |
Output is correct |
28 |
Correct |
49 ms |
5204 KB |
Output is correct |
29 |
Correct |
39 ms |
5244 KB |
Output is correct |
30 |
Correct |
38 ms |
5204 KB |
Output is correct |
31 |
Correct |
41 ms |
5204 KB |
Output is correct |
32 |
Correct |
42 ms |
5244 KB |
Output is correct |
33 |
Correct |
44 ms |
5204 KB |
Output is correct |
34 |
Correct |
52 ms |
5232 KB |
Output is correct |
35 |
Correct |
45 ms |
5224 KB |
Output is correct |
36 |
Correct |
40 ms |
5212 KB |
Output is correct |
37 |
Correct |
37 ms |
5208 KB |
Output is correct |
38 |
Correct |
45 ms |
5216 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
5012 KB |
Output is correct |
2 |
Correct |
4 ms |
5020 KB |
Output is correct |
3 |
Correct |
3 ms |
5012 KB |
Output is correct |
4 |
Correct |
3 ms |
5032 KB |
Output is correct |
5 |
Correct |
3 ms |
4980 KB |
Output is correct |
6 |
Correct |
3 ms |
4948 KB |
Output is correct |
7 |
Correct |
3 ms |
5076 KB |
Output is correct |
8 |
Correct |
3 ms |
5016 KB |
Output is correct |
9 |
Correct |
3 ms |
5020 KB |
Output is correct |
10 |
Correct |
4 ms |
5016 KB |
Output is correct |
11 |
Correct |
3 ms |
4948 KB |
Output is correct |
12 |
Correct |
3 ms |
4948 KB |
Output is correct |
13 |
Correct |
3 ms |
5020 KB |
Output is correct |
14 |
Correct |
4 ms |
5016 KB |
Output is correct |
15 |
Correct |
3 ms |
5004 KB |
Output is correct |
16 |
Correct |
5 ms |
5068 KB |
Output is correct |
17 |
Correct |
4 ms |
4948 KB |
Output is correct |
18 |
Correct |
3 ms |
4948 KB |
Output is correct |
19 |
Execution timed out |
3049 ms |
27128 KB |
Time limit exceeded |
20 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
5012 KB |
Output is correct |
2 |
Correct |
4 ms |
5020 KB |
Output is correct |
3 |
Correct |
3 ms |
5012 KB |
Output is correct |
4 |
Correct |
3 ms |
5032 KB |
Output is correct |
5 |
Correct |
3 ms |
4980 KB |
Output is correct |
6 |
Correct |
3 ms |
4948 KB |
Output is correct |
7 |
Correct |
3 ms |
5076 KB |
Output is correct |
8 |
Correct |
3 ms |
5016 KB |
Output is correct |
9 |
Correct |
3 ms |
5020 KB |
Output is correct |
10 |
Correct |
4 ms |
5016 KB |
Output is correct |
11 |
Correct |
3 ms |
4948 KB |
Output is correct |
12 |
Correct |
3 ms |
4948 KB |
Output is correct |
13 |
Correct |
3 ms |
5020 KB |
Output is correct |
14 |
Correct |
4 ms |
5016 KB |
Output is correct |
15 |
Correct |
3 ms |
5004 KB |
Output is correct |
16 |
Correct |
5 ms |
5068 KB |
Output is correct |
17 |
Correct |
4 ms |
4948 KB |
Output is correct |
18 |
Correct |
3 ms |
4948 KB |
Output is correct |
19 |
Correct |
3 ms |
4948 KB |
Output is correct |
20 |
Correct |
3 ms |
4948 KB |
Output is correct |
21 |
Correct |
43 ms |
5204 KB |
Output is correct |
22 |
Correct |
46 ms |
5204 KB |
Output is correct |
23 |
Correct |
45 ms |
5264 KB |
Output is correct |
24 |
Correct |
43 ms |
5244 KB |
Output is correct |
25 |
Correct |
46 ms |
5156 KB |
Output is correct |
26 |
Correct |
48 ms |
5244 KB |
Output is correct |
27 |
Correct |
42 ms |
5240 KB |
Output is correct |
28 |
Correct |
49 ms |
5204 KB |
Output is correct |
29 |
Correct |
39 ms |
5244 KB |
Output is correct |
30 |
Correct |
38 ms |
5204 KB |
Output is correct |
31 |
Correct |
41 ms |
5204 KB |
Output is correct |
32 |
Correct |
42 ms |
5244 KB |
Output is correct |
33 |
Correct |
44 ms |
5204 KB |
Output is correct |
34 |
Correct |
52 ms |
5232 KB |
Output is correct |
35 |
Correct |
45 ms |
5224 KB |
Output is correct |
36 |
Correct |
40 ms |
5212 KB |
Output is correct |
37 |
Correct |
37 ms |
5208 KB |
Output is correct |
38 |
Correct |
45 ms |
5216 KB |
Output is correct |
39 |
Execution timed out |
3049 ms |
27128 KB |
Time limit exceeded |
40 |
Halted |
0 ms |
0 KB |
- |