# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1084283 |
2024-09-05T18:16:58 Z |
EkinOnal |
Race (IOI11_race) |
C++17 |
|
338 ms |
37716 KB |
#include "race.h"
#include <bits/stdc++.h>
using namespace std;
#define MAX 200000
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define vi vector<int>
#define pii pair<int,int>
#define si set<int>
#define vpii vector<pair<int,int>>
const int mod = 1e9+7;
const int INF = 1e9;
int n,k,cev;
vpii adj[MAX];
vi dead(MAX),sz(MAX),mpp(1e6+5);
void dfs(int node,int par){
sz[node]=1;
for(auto u : adj[node]){
if(dead[u.f] || u.f==par) continue;
dfs(u.f,node);
sz[node]+=sz[u.f];
}
}
int findc(int node,int par,int val){
for(auto u : adj[node]){
if(dead[u.f] || u.f==par) continue;
if(sz[u.f]>=val/2) return findc(u.f,node,val); // val olmalidir
}
return node;
}
void check(int node,int par,int len,int sayi){
if(len>k) return;
if(mpp[k-len]!=INF) cev=min(cev,mpp[k-len]+sayi);
for(auto u : adj[node]){
if(dead[u.f] || u.f==par) continue;
check(u.f,node,len+u.s,sayi+1);
}
}
void build(int node,int par,int len,int sayi){
if(len>k) return;
// if(mpp[len]==INF) mpp[len]=sayi;
mpp[len]=min(mpp[len],sayi);
for(auto u : adj[node]){
if(dead[u.f] || u.f==par) continue;
build(u.f,node,len+u.s,sayi+1);
}
}
void sifirla(int node,int par,int der){
if(der>k) return;
mpp[der]=INF;
for(auto u : adj[node]){
if(dead[u.f] || u.f==par) continue;
sifirla(u.f,node,der+u.s);
}
}
void solve(int node){
dfs(node,node);
int x = findc(node,node,sz[node]);
dead[x]=true;
mpp[0]=0;
for(auto u : adj[x]){
if(dead[u.f]) continue;
check(u.f,x,u.s,1);
build(u.f,x,u.s,1);
}
for(auto u : adj[x]){
if(dead[u.f]) continue;
sifirla(u.f,x,u.s);
}
for(auto u : adj[x]){
if(dead[u.f]) continue;
solve(u.f);
}
}
int best_path(int N, int K, int H[][2], int L[])
{
n=N,k=K;
for(int i=0;i<n-1;i++){
adj[H[i][0]].pb({H[i][1],L[i]});
adj[H[i][1]].pb({H[i][0],L[i]});
}
fill(mpp.begin(),mpp.end(),INF);
cev=n+2;
solve(0);
if(cev==n+2) cev=-1;
return cev;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
10584 KB |
Output is correct |
2 |
Correct |
5 ms |
10588 KB |
Output is correct |
3 |
Correct |
4 ms |
10572 KB |
Output is correct |
4 |
Correct |
5 ms |
10588 KB |
Output is correct |
5 |
Correct |
5 ms |
10584 KB |
Output is correct |
6 |
Correct |
5 ms |
10588 KB |
Output is correct |
7 |
Correct |
6 ms |
10560 KB |
Output is correct |
8 |
Correct |
7 ms |
10588 KB |
Output is correct |
9 |
Correct |
5 ms |
10588 KB |
Output is correct |
10 |
Correct |
5 ms |
10588 KB |
Output is correct |
11 |
Correct |
6 ms |
10584 KB |
Output is correct |
12 |
Correct |
5 ms |
10588 KB |
Output is correct |
13 |
Correct |
5 ms |
10588 KB |
Output is correct |
14 |
Correct |
5 ms |
10584 KB |
Output is correct |
15 |
Correct |
7 ms |
10644 KB |
Output is correct |
16 |
Correct |
5 ms |
10588 KB |
Output is correct |
17 |
Correct |
5 ms |
10588 KB |
Output is correct |
18 |
Correct |
5 ms |
10588 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
10584 KB |
Output is correct |
2 |
Correct |
5 ms |
10588 KB |
Output is correct |
3 |
Correct |
4 ms |
10572 KB |
Output is correct |
4 |
Correct |
5 ms |
10588 KB |
Output is correct |
5 |
Correct |
5 ms |
10584 KB |
Output is correct |
6 |
Correct |
5 ms |
10588 KB |
Output is correct |
7 |
Correct |
6 ms |
10560 KB |
Output is correct |
8 |
Correct |
7 ms |
10588 KB |
Output is correct |
9 |
Correct |
5 ms |
10588 KB |
Output is correct |
10 |
Correct |
5 ms |
10588 KB |
Output is correct |
11 |
Correct |
6 ms |
10584 KB |
Output is correct |
12 |
Correct |
5 ms |
10588 KB |
Output is correct |
13 |
Correct |
5 ms |
10588 KB |
Output is correct |
14 |
Correct |
5 ms |
10584 KB |
Output is correct |
15 |
Correct |
7 ms |
10644 KB |
Output is correct |
16 |
Correct |
5 ms |
10588 KB |
Output is correct |
17 |
Correct |
5 ms |
10588 KB |
Output is correct |
18 |
Correct |
5 ms |
10588 KB |
Output is correct |
19 |
Correct |
7 ms |
10584 KB |
Output is correct |
20 |
Correct |
8 ms |
10588 KB |
Output is correct |
21 |
Correct |
6 ms |
10588 KB |
Output is correct |
22 |
Correct |
5 ms |
10584 KB |
Output is correct |
23 |
Correct |
6 ms |
10584 KB |
Output is correct |
24 |
Correct |
5 ms |
10588 KB |
Output is correct |
25 |
Correct |
5 ms |
10588 KB |
Output is correct |
26 |
Correct |
5 ms |
10588 KB |
Output is correct |
27 |
Correct |
6 ms |
10584 KB |
Output is correct |
28 |
Correct |
5 ms |
10588 KB |
Output is correct |
29 |
Correct |
5 ms |
10588 KB |
Output is correct |
30 |
Correct |
5 ms |
10588 KB |
Output is correct |
31 |
Correct |
5 ms |
10588 KB |
Output is correct |
32 |
Correct |
6 ms |
10584 KB |
Output is correct |
33 |
Correct |
5 ms |
10588 KB |
Output is correct |
34 |
Correct |
5 ms |
10624 KB |
Output is correct |
35 |
Correct |
5 ms |
10588 KB |
Output is correct |
36 |
Correct |
5 ms |
10516 KB |
Output is correct |
37 |
Correct |
6 ms |
10588 KB |
Output is correct |
38 |
Correct |
6 ms |
10588 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
10584 KB |
Output is correct |
2 |
Correct |
5 ms |
10588 KB |
Output is correct |
3 |
Correct |
4 ms |
10572 KB |
Output is correct |
4 |
Correct |
5 ms |
10588 KB |
Output is correct |
5 |
Correct |
5 ms |
10584 KB |
Output is correct |
6 |
Correct |
5 ms |
10588 KB |
Output is correct |
7 |
Correct |
6 ms |
10560 KB |
Output is correct |
8 |
Correct |
7 ms |
10588 KB |
Output is correct |
9 |
Correct |
5 ms |
10588 KB |
Output is correct |
10 |
Correct |
5 ms |
10588 KB |
Output is correct |
11 |
Correct |
6 ms |
10584 KB |
Output is correct |
12 |
Correct |
5 ms |
10588 KB |
Output is correct |
13 |
Correct |
5 ms |
10588 KB |
Output is correct |
14 |
Correct |
5 ms |
10584 KB |
Output is correct |
15 |
Correct |
7 ms |
10644 KB |
Output is correct |
16 |
Correct |
5 ms |
10588 KB |
Output is correct |
17 |
Correct |
5 ms |
10588 KB |
Output is correct |
18 |
Correct |
5 ms |
10588 KB |
Output is correct |
19 |
Correct |
100 ms |
16724 KB |
Output is correct |
20 |
Correct |
90 ms |
16720 KB |
Output is correct |
21 |
Correct |
100 ms |
16732 KB |
Output is correct |
22 |
Correct |
95 ms |
16732 KB |
Output is correct |
23 |
Correct |
51 ms |
16980 KB |
Output is correct |
24 |
Correct |
49 ms |
16976 KB |
Output is correct |
25 |
Correct |
97 ms |
20560 KB |
Output is correct |
26 |
Correct |
77 ms |
23920 KB |
Output is correct |
27 |
Correct |
103 ms |
23444 KB |
Output is correct |
28 |
Correct |
178 ms |
37716 KB |
Output is correct |
29 |
Correct |
161 ms |
36732 KB |
Output is correct |
30 |
Correct |
111 ms |
23380 KB |
Output is correct |
31 |
Correct |
106 ms |
23380 KB |
Output is correct |
32 |
Correct |
131 ms |
23556 KB |
Output is correct |
33 |
Correct |
145 ms |
22096 KB |
Output is correct |
34 |
Correct |
117 ms |
23184 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
10584 KB |
Output is correct |
2 |
Correct |
5 ms |
10588 KB |
Output is correct |
3 |
Correct |
4 ms |
10572 KB |
Output is correct |
4 |
Correct |
5 ms |
10588 KB |
Output is correct |
5 |
Correct |
5 ms |
10584 KB |
Output is correct |
6 |
Correct |
5 ms |
10588 KB |
Output is correct |
7 |
Correct |
6 ms |
10560 KB |
Output is correct |
8 |
Correct |
7 ms |
10588 KB |
Output is correct |
9 |
Correct |
5 ms |
10588 KB |
Output is correct |
10 |
Correct |
5 ms |
10588 KB |
Output is correct |
11 |
Correct |
6 ms |
10584 KB |
Output is correct |
12 |
Correct |
5 ms |
10588 KB |
Output is correct |
13 |
Correct |
5 ms |
10588 KB |
Output is correct |
14 |
Correct |
5 ms |
10584 KB |
Output is correct |
15 |
Correct |
7 ms |
10644 KB |
Output is correct |
16 |
Correct |
5 ms |
10588 KB |
Output is correct |
17 |
Correct |
5 ms |
10588 KB |
Output is correct |
18 |
Correct |
5 ms |
10588 KB |
Output is correct |
19 |
Correct |
7 ms |
10584 KB |
Output is correct |
20 |
Correct |
8 ms |
10588 KB |
Output is correct |
21 |
Correct |
6 ms |
10588 KB |
Output is correct |
22 |
Correct |
5 ms |
10584 KB |
Output is correct |
23 |
Correct |
6 ms |
10584 KB |
Output is correct |
24 |
Correct |
5 ms |
10588 KB |
Output is correct |
25 |
Correct |
5 ms |
10588 KB |
Output is correct |
26 |
Correct |
5 ms |
10588 KB |
Output is correct |
27 |
Correct |
6 ms |
10584 KB |
Output is correct |
28 |
Correct |
5 ms |
10588 KB |
Output is correct |
29 |
Correct |
5 ms |
10588 KB |
Output is correct |
30 |
Correct |
5 ms |
10588 KB |
Output is correct |
31 |
Correct |
5 ms |
10588 KB |
Output is correct |
32 |
Correct |
6 ms |
10584 KB |
Output is correct |
33 |
Correct |
5 ms |
10588 KB |
Output is correct |
34 |
Correct |
5 ms |
10624 KB |
Output is correct |
35 |
Correct |
5 ms |
10588 KB |
Output is correct |
36 |
Correct |
5 ms |
10516 KB |
Output is correct |
37 |
Correct |
6 ms |
10588 KB |
Output is correct |
38 |
Correct |
6 ms |
10588 KB |
Output is correct |
39 |
Correct |
100 ms |
16724 KB |
Output is correct |
40 |
Correct |
90 ms |
16720 KB |
Output is correct |
41 |
Correct |
100 ms |
16732 KB |
Output is correct |
42 |
Correct |
95 ms |
16732 KB |
Output is correct |
43 |
Correct |
51 ms |
16980 KB |
Output is correct |
44 |
Correct |
49 ms |
16976 KB |
Output is correct |
45 |
Correct |
97 ms |
20560 KB |
Output is correct |
46 |
Correct |
77 ms |
23920 KB |
Output is correct |
47 |
Correct |
103 ms |
23444 KB |
Output is correct |
48 |
Correct |
178 ms |
37716 KB |
Output is correct |
49 |
Correct |
161 ms |
36732 KB |
Output is correct |
50 |
Correct |
111 ms |
23380 KB |
Output is correct |
51 |
Correct |
106 ms |
23380 KB |
Output is correct |
52 |
Correct |
131 ms |
23556 KB |
Output is correct |
53 |
Correct |
145 ms |
22096 KB |
Output is correct |
54 |
Correct |
117 ms |
23184 KB |
Output is correct |
55 |
Correct |
12 ms |
11220 KB |
Output is correct |
56 |
Correct |
12 ms |
11100 KB |
Output is correct |
57 |
Correct |
51 ms |
17056 KB |
Output is correct |
58 |
Correct |
26 ms |
16584 KB |
Output is correct |
59 |
Correct |
77 ms |
24076 KB |
Output is correct |
60 |
Correct |
338 ms |
36796 KB |
Output is correct |
61 |
Correct |
117 ms |
23380 KB |
Output is correct |
62 |
Correct |
163 ms |
23376 KB |
Output is correct |
63 |
Correct |
157 ms |
23376 KB |
Output is correct |
64 |
Correct |
311 ms |
23732 KB |
Output is correct |
65 |
Correct |
144 ms |
24144 KB |
Output is correct |
66 |
Correct |
253 ms |
34128 KB |
Output is correct |
67 |
Correct |
78 ms |
24040 KB |
Output is correct |
68 |
Correct |
152 ms |
24144 KB |
Output is correct |
69 |
Correct |
148 ms |
24404 KB |
Output is correct |
70 |
Correct |
147 ms |
23556 KB |
Output is correct |