# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1103033 |
2024-10-19T14:32:25 Z |
InvMOD |
Race (IOI11_race) |
C++14 |
|
226 ms |
38388 KB |
#include<bits/stdc++.h>
#define fi first
#define se second
using namespace std;
template<typename T> bool ckmn(T& a, const T& b){if(a > b) return a = b, true; return false;}
const int _N = 2e5+5, _K = 1e6+5, inf = 1e9;
int n, k, sz[_N];
int MinDist[_K], miniDist;
bool del[_N];
vector<pair<int,int>> adj[_N];
int get_Size(int x, int p){
sz[x] = 1;
for(pair<int,int> e : adj[x]){
int v = e.fi;
if(v != p && !del[v]){
sz[x] += get_Size(v, x);
}
}
return sz[x];
}
int Centroid(int x, int p, int trsz){
for(pair<int,int> e : adj[x]){
int v = e.fi;
if(v != p && !del[v]){
if((sz[v]<<1) > trsz){
return Centroid(v, x, trsz);
}
}
}
return x;
}
queue<int> save;
stack<pair<int,int>> subtr;
void dfs(int x, int p, int cur_dist, int cur_height){
if(MinDist[k - cur_dist] != inf){
ckmn(miniDist, MinDist[k - cur_dist] + cur_height);
}
for(pair<int,int> e : adj[x]){
int v = e.fi, w = e.se;
if(del[v] || v == p) continue;
if(cur_dist <= k - w && cur_height+1 <= miniDist) dfs(v, x, cur_dist+w, cur_height+1);
if(p == -1){
while(!subtr.empty()){
pair<int,int> info = subtr.top(); subtr.pop();
int dist = info.fi, mnH = info.se;
ckmn(MinDist[dist], mnH);
}
}
}
if(p != -1){
save.push(cur_dist);
subtr.push(make_pair(cur_dist, cur_height));
}
else{
while(!save.empty()){
int dist = save.front(); save.pop();
MinDist[dist] = inf;
}
}
return;
}
void decompose(int x){
x = Centroid(x, -1, get_Size(x, -1));
del[x] = true;
dfs(x, -1, 0, 0);
for(pair<int,int> e : adj[x]){
int v = e.fi;
if(!del[v]) decompose(v);
}
return;
}
int best_path(int N, int K, int H[][2], int L[])
{
n = N, k = K;
for(int i = 0; i < n-1; i++){
int u = H[i][0]+1, v = H[i][1]+1, w = L[i];
adj[u].push_back(make_pair(v, w));
adj[v].push_back(make_pair(u, w));
}
miniDist = inf;
for(int i = 1; i <= k; i++){
MinDist[i] = inf;
}
decompose(1);
return (miniDist == inf ? -1 : miniDist);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
10580 KB |
Output is correct |
2 |
Correct |
2 ms |
10580 KB |
Output is correct |
3 |
Correct |
2 ms |
10580 KB |
Output is correct |
4 |
Correct |
3 ms |
10580 KB |
Output is correct |
5 |
Correct |
2 ms |
10580 KB |
Output is correct |
6 |
Correct |
2 ms |
10580 KB |
Output is correct |
7 |
Correct |
3 ms |
10708 KB |
Output is correct |
8 |
Correct |
2 ms |
10580 KB |
Output is correct |
9 |
Correct |
2 ms |
10580 KB |
Output is correct |
10 |
Correct |
3 ms |
10580 KB |
Output is correct |
11 |
Correct |
2 ms |
10580 KB |
Output is correct |
12 |
Correct |
2 ms |
10580 KB |
Output is correct |
13 |
Correct |
2 ms |
10580 KB |
Output is correct |
14 |
Correct |
2 ms |
10580 KB |
Output is correct |
15 |
Correct |
2 ms |
10580 KB |
Output is correct |
16 |
Correct |
2 ms |
10580 KB |
Output is correct |
17 |
Correct |
2 ms |
10580 KB |
Output is correct |
18 |
Correct |
2 ms |
10836 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
10580 KB |
Output is correct |
2 |
Correct |
2 ms |
10580 KB |
Output is correct |
3 |
Correct |
2 ms |
10580 KB |
Output is correct |
4 |
Correct |
3 ms |
10580 KB |
Output is correct |
5 |
Correct |
2 ms |
10580 KB |
Output is correct |
6 |
Correct |
2 ms |
10580 KB |
Output is correct |
7 |
Correct |
3 ms |
10708 KB |
Output is correct |
8 |
Correct |
2 ms |
10580 KB |
Output is correct |
9 |
Correct |
2 ms |
10580 KB |
Output is correct |
10 |
Correct |
3 ms |
10580 KB |
Output is correct |
11 |
Correct |
2 ms |
10580 KB |
Output is correct |
12 |
Correct |
2 ms |
10580 KB |
Output is correct |
13 |
Correct |
2 ms |
10580 KB |
Output is correct |
14 |
Correct |
2 ms |
10580 KB |
Output is correct |
15 |
Correct |
2 ms |
10580 KB |
Output is correct |
16 |
Correct |
2 ms |
10580 KB |
Output is correct |
17 |
Correct |
2 ms |
10580 KB |
Output is correct |
18 |
Correct |
2 ms |
10836 KB |
Output is correct |
19 |
Correct |
2 ms |
10580 KB |
Output is correct |
20 |
Correct |
2 ms |
10580 KB |
Output is correct |
21 |
Correct |
2 ms |
10580 KB |
Output is correct |
22 |
Correct |
3 ms |
12628 KB |
Output is correct |
23 |
Correct |
2 ms |
12628 KB |
Output is correct |
24 |
Correct |
3 ms |
12628 KB |
Output is correct |
25 |
Correct |
3 ms |
12628 KB |
Output is correct |
26 |
Correct |
2 ms |
10724 KB |
Output is correct |
27 |
Correct |
3 ms |
12628 KB |
Output is correct |
28 |
Correct |
3 ms |
10836 KB |
Output is correct |
29 |
Correct |
2 ms |
10580 KB |
Output is correct |
30 |
Correct |
2 ms |
10580 KB |
Output is correct |
31 |
Correct |
3 ms |
12628 KB |
Output is correct |
32 |
Correct |
3 ms |
12772 KB |
Output is correct |
33 |
Correct |
3 ms |
12628 KB |
Output is correct |
34 |
Correct |
3 ms |
12628 KB |
Output is correct |
35 |
Correct |
3 ms |
12628 KB |
Output is correct |
36 |
Correct |
3 ms |
12852 KB |
Output is correct |
37 |
Correct |
3 ms |
12628 KB |
Output is correct |
38 |
Correct |
2 ms |
12628 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
10580 KB |
Output is correct |
2 |
Correct |
2 ms |
10580 KB |
Output is correct |
3 |
Correct |
2 ms |
10580 KB |
Output is correct |
4 |
Correct |
3 ms |
10580 KB |
Output is correct |
5 |
Correct |
2 ms |
10580 KB |
Output is correct |
6 |
Correct |
2 ms |
10580 KB |
Output is correct |
7 |
Correct |
3 ms |
10708 KB |
Output is correct |
8 |
Correct |
2 ms |
10580 KB |
Output is correct |
9 |
Correct |
2 ms |
10580 KB |
Output is correct |
10 |
Correct |
3 ms |
10580 KB |
Output is correct |
11 |
Correct |
2 ms |
10580 KB |
Output is correct |
12 |
Correct |
2 ms |
10580 KB |
Output is correct |
13 |
Correct |
2 ms |
10580 KB |
Output is correct |
14 |
Correct |
2 ms |
10580 KB |
Output is correct |
15 |
Correct |
2 ms |
10580 KB |
Output is correct |
16 |
Correct |
2 ms |
10580 KB |
Output is correct |
17 |
Correct |
2 ms |
10580 KB |
Output is correct |
18 |
Correct |
2 ms |
10836 KB |
Output is correct |
19 |
Correct |
79 ms |
18252 KB |
Output is correct |
20 |
Correct |
59 ms |
18344 KB |
Output is correct |
21 |
Correct |
64 ms |
18252 KB |
Output is correct |
22 |
Correct |
65 ms |
18508 KB |
Output is correct |
23 |
Correct |
40 ms |
18528 KB |
Output is correct |
24 |
Correct |
33 ms |
18564 KB |
Output is correct |
25 |
Correct |
74 ms |
21068 KB |
Output is correct |
26 |
Correct |
66 ms |
24664 KB |
Output is correct |
27 |
Correct |
94 ms |
24152 KB |
Output is correct |
28 |
Correct |
133 ms |
35444 KB |
Output is correct |
29 |
Correct |
136 ms |
34636 KB |
Output is correct |
30 |
Correct |
95 ms |
24068 KB |
Output is correct |
31 |
Correct |
85 ms |
24140 KB |
Output is correct |
32 |
Correct |
99 ms |
24140 KB |
Output is correct |
33 |
Correct |
112 ms |
23016 KB |
Output is correct |
34 |
Correct |
98 ms |
23884 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
10580 KB |
Output is correct |
2 |
Correct |
2 ms |
10580 KB |
Output is correct |
3 |
Correct |
2 ms |
10580 KB |
Output is correct |
4 |
Correct |
3 ms |
10580 KB |
Output is correct |
5 |
Correct |
2 ms |
10580 KB |
Output is correct |
6 |
Correct |
2 ms |
10580 KB |
Output is correct |
7 |
Correct |
3 ms |
10708 KB |
Output is correct |
8 |
Correct |
2 ms |
10580 KB |
Output is correct |
9 |
Correct |
2 ms |
10580 KB |
Output is correct |
10 |
Correct |
3 ms |
10580 KB |
Output is correct |
11 |
Correct |
2 ms |
10580 KB |
Output is correct |
12 |
Correct |
2 ms |
10580 KB |
Output is correct |
13 |
Correct |
2 ms |
10580 KB |
Output is correct |
14 |
Correct |
2 ms |
10580 KB |
Output is correct |
15 |
Correct |
2 ms |
10580 KB |
Output is correct |
16 |
Correct |
2 ms |
10580 KB |
Output is correct |
17 |
Correct |
2 ms |
10580 KB |
Output is correct |
18 |
Correct |
2 ms |
10836 KB |
Output is correct |
19 |
Correct |
2 ms |
10580 KB |
Output is correct |
20 |
Correct |
2 ms |
10580 KB |
Output is correct |
21 |
Correct |
2 ms |
10580 KB |
Output is correct |
22 |
Correct |
3 ms |
12628 KB |
Output is correct |
23 |
Correct |
2 ms |
12628 KB |
Output is correct |
24 |
Correct |
3 ms |
12628 KB |
Output is correct |
25 |
Correct |
3 ms |
12628 KB |
Output is correct |
26 |
Correct |
2 ms |
10724 KB |
Output is correct |
27 |
Correct |
3 ms |
12628 KB |
Output is correct |
28 |
Correct |
3 ms |
10836 KB |
Output is correct |
29 |
Correct |
2 ms |
10580 KB |
Output is correct |
30 |
Correct |
2 ms |
10580 KB |
Output is correct |
31 |
Correct |
3 ms |
12628 KB |
Output is correct |
32 |
Correct |
3 ms |
12772 KB |
Output is correct |
33 |
Correct |
3 ms |
12628 KB |
Output is correct |
34 |
Correct |
3 ms |
12628 KB |
Output is correct |
35 |
Correct |
3 ms |
12628 KB |
Output is correct |
36 |
Correct |
3 ms |
12852 KB |
Output is correct |
37 |
Correct |
3 ms |
12628 KB |
Output is correct |
38 |
Correct |
2 ms |
12628 KB |
Output is correct |
39 |
Correct |
79 ms |
18252 KB |
Output is correct |
40 |
Correct |
59 ms |
18344 KB |
Output is correct |
41 |
Correct |
64 ms |
18252 KB |
Output is correct |
42 |
Correct |
65 ms |
18508 KB |
Output is correct |
43 |
Correct |
40 ms |
18528 KB |
Output is correct |
44 |
Correct |
33 ms |
18564 KB |
Output is correct |
45 |
Correct |
74 ms |
21068 KB |
Output is correct |
46 |
Correct |
66 ms |
24664 KB |
Output is correct |
47 |
Correct |
94 ms |
24152 KB |
Output is correct |
48 |
Correct |
133 ms |
35444 KB |
Output is correct |
49 |
Correct |
136 ms |
34636 KB |
Output is correct |
50 |
Correct |
95 ms |
24068 KB |
Output is correct |
51 |
Correct |
85 ms |
24140 KB |
Output is correct |
52 |
Correct |
99 ms |
24140 KB |
Output is correct |
53 |
Correct |
112 ms |
23016 KB |
Output is correct |
54 |
Correct |
98 ms |
23884 KB |
Output is correct |
55 |
Correct |
6 ms |
11092 KB |
Output is correct |
56 |
Correct |
7 ms |
11348 KB |
Output is correct |
57 |
Correct |
49 ms |
19192 KB |
Output is correct |
58 |
Correct |
38 ms |
18512 KB |
Output is correct |
59 |
Correct |
70 ms |
24828 KB |
Output is correct |
60 |
Correct |
226 ms |
38388 KB |
Output is correct |
61 |
Correct |
105 ms |
24396 KB |
Output is correct |
62 |
Correct |
120 ms |
27212 KB |
Output is correct |
63 |
Correct |
140 ms |
27248 KB |
Output is correct |
64 |
Correct |
206 ms |
27724 KB |
Output is correct |
65 |
Correct |
113 ms |
24908 KB |
Output is correct |
66 |
Correct |
188 ms |
34892 KB |
Output is correct |
67 |
Correct |
61 ms |
28348 KB |
Output is correct |
68 |
Correct |
116 ms |
27212 KB |
Output is correct |
69 |
Correct |
95 ms |
27124 KB |
Output is correct |
70 |
Correct |
96 ms |
26608 KB |
Output is correct |