Submission #884691

# Submission time Handle Problem Language Result Execution time Memory
884691 2023-12-08T04:49:29 Z tamir1 Race (IOI11_race) C++14
100 / 100
1037 ms 49192 KB
#include "race.h"
#include<bits/stdc++.h>
#define ll int
#define pp pair<ll,ll>
#define f first
#define s second
using namespace std;
ll i,a,b,ans=200010,sz[200001],k;
bitset<200001> mark;
map<ll,ll> mp;
vector<pp> G[200001];
ll getsize(ll a,ll p=-1){
	sz[a]=1;
	for(pp i:G[a]){
		if(p!=i.f && !mark[i.f]) 
			sz[a]+=getsize(i.f,a);
	}
	return sz[a];
}
ll centroid(ll a,ll p,ll n){
	for(pp i:G[a]){
		if(p!=i.f && sz[i.f]>n/2 && !mark[i.f])
			return centroid(i.f,a,n);
	}
	return a;
}
void dfs(ll a,ll p,ll dist,ll len,bool key){
	if(dist>k) return;
	if(dist==k){
		ans=min(ans,len);
		return;
	}
	if(key){
		if(mp[k-dist]) 
			ans=min(ans,len+mp[k-dist]);
	}
	else{
		if(!mp[dist]) mp[dist]=len;
		else mp[dist]=min(mp[dist],len);
	}
	for(pp i:G[a]){
		if(p!=i.f && !mark[i.f]){
			dfs(i.f,a,dist+i.s,len+1,key);
		}	
	}
}
void solve(ll a){
	ll n,cnt;
	n=getsize(a);
	cnt=centroid(a,0,n);
	mark[cnt]=1;
	mp.clear();
	for(pp i:G[cnt]){
		if(!mark[i.f]){
			dfs(i.f,cnt,i.s,1,1);
			dfs(i.f,cnt,i.s,1,0);
		}
	}
	for(pp i:G[cnt]){
		if(!mark[i.f])
			solve(i.f);
	}
}
int best_path(int N,int K,int H[][2],int L[]){
	k=K;
	for(i=0;i<N-1;i++){
		a=H[i][0]+1;
		b=H[i][1]+1;
		G[a].push_back({b,L[i]});
		G[b].push_back({a,L[i]});
	}
	solve(1);
	if(ans==200010) return -1;
	return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 8792 KB Output is correct
2 Correct 2 ms 8792 KB Output is correct
3 Correct 2 ms 8792 KB Output is correct
4 Correct 2 ms 8792 KB Output is correct
5 Correct 2 ms 8952 KB Output is correct
6 Correct 2 ms 8796 KB Output is correct
7 Correct 2 ms 8796 KB Output is correct
8 Correct 2 ms 8796 KB Output is correct
9 Correct 2 ms 8796 KB Output is correct
10 Correct 2 ms 8784 KB Output is correct
11 Correct 2 ms 8796 KB Output is correct
12 Correct 2 ms 8796 KB Output is correct
13 Correct 2 ms 8796 KB Output is correct
14 Correct 2 ms 8792 KB Output is correct
15 Correct 2 ms 8796 KB Output is correct
16 Correct 2 ms 8796 KB Output is correct
17 Correct 2 ms 8796 KB Output is correct
18 Correct 2 ms 8796 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 8792 KB Output is correct
2 Correct 2 ms 8792 KB Output is correct
3 Correct 2 ms 8792 KB Output is correct
4 Correct 2 ms 8792 KB Output is correct
5 Correct 2 ms 8952 KB Output is correct
6 Correct 2 ms 8796 KB Output is correct
7 Correct 2 ms 8796 KB Output is correct
8 Correct 2 ms 8796 KB Output is correct
9 Correct 2 ms 8796 KB Output is correct
10 Correct 2 ms 8784 KB Output is correct
11 Correct 2 ms 8796 KB Output is correct
12 Correct 2 ms 8796 KB Output is correct
13 Correct 2 ms 8796 KB Output is correct
14 Correct 2 ms 8792 KB Output is correct
15 Correct 2 ms 8796 KB Output is correct
16 Correct 2 ms 8796 KB Output is correct
17 Correct 2 ms 8796 KB Output is correct
18 Correct 2 ms 8796 KB Output is correct
19 Correct 2 ms 8796 KB Output is correct
20 Correct 2 ms 8616 KB Output is correct
21 Correct 3 ms 8796 KB Output is correct
22 Correct 2 ms 8796 KB Output is correct
23 Correct 3 ms 8796 KB Output is correct
24 Correct 2 ms 8796 KB Output is correct
25 Correct 3 ms 8796 KB Output is correct
26 Correct 2 ms 8796 KB Output is correct
27 Correct 2 ms 8796 KB Output is correct
28 Correct 3 ms 8796 KB Output is correct
29 Correct 4 ms 8796 KB Output is correct
30 Correct 3 ms 8796 KB Output is correct
31 Correct 3 ms 8796 KB Output is correct
32 Correct 4 ms 8796 KB Output is correct
33 Correct 4 ms 8796 KB Output is correct
34 Correct 3 ms 8860 KB Output is correct
35 Correct 3 ms 8796 KB Output is correct
36 Correct 3 ms 8796 KB Output is correct
37 Correct 3 ms 8796 KB Output is correct
38 Correct 3 ms 8796 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 8792 KB Output is correct
2 Correct 2 ms 8792 KB Output is correct
3 Correct 2 ms 8792 KB Output is correct
4 Correct 2 ms 8792 KB Output is correct
5 Correct 2 ms 8952 KB Output is correct
6 Correct 2 ms 8796 KB Output is correct
7 Correct 2 ms 8796 KB Output is correct
8 Correct 2 ms 8796 KB Output is correct
9 Correct 2 ms 8796 KB Output is correct
10 Correct 2 ms 8784 KB Output is correct
11 Correct 2 ms 8796 KB Output is correct
12 Correct 2 ms 8796 KB Output is correct
13 Correct 2 ms 8796 KB Output is correct
14 Correct 2 ms 8792 KB Output is correct
15 Correct 2 ms 8796 KB Output is correct
16 Correct 2 ms 8796 KB Output is correct
17 Correct 2 ms 8796 KB Output is correct
18 Correct 2 ms 8796 KB Output is correct
19 Correct 173 ms 16212 KB Output is correct
20 Correct 176 ms 16408 KB Output is correct
21 Correct 198 ms 16212 KB Output is correct
22 Correct 174 ms 16468 KB Output is correct
23 Correct 80 ms 16724 KB Output is correct
24 Correct 62 ms 16864 KB Output is correct
25 Correct 124 ms 19320 KB Output is correct
26 Correct 86 ms 22092 KB Output is correct
27 Correct 170 ms 22244 KB Output is correct
28 Correct 206 ms 33596 KB Output is correct
29 Correct 170 ms 32680 KB Output is correct
30 Correct 182 ms 22096 KB Output is correct
31 Correct 160 ms 22096 KB Output is correct
32 Correct 184 ms 22168 KB Output is correct
33 Correct 241 ms 21344 KB Output is correct
34 Correct 108 ms 22016 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 8792 KB Output is correct
2 Correct 2 ms 8792 KB Output is correct
3 Correct 2 ms 8792 KB Output is correct
4 Correct 2 ms 8792 KB Output is correct
5 Correct 2 ms 8952 KB Output is correct
6 Correct 2 ms 8796 KB Output is correct
7 Correct 2 ms 8796 KB Output is correct
8 Correct 2 ms 8796 KB Output is correct
9 Correct 2 ms 8796 KB Output is correct
10 Correct 2 ms 8784 KB Output is correct
11 Correct 2 ms 8796 KB Output is correct
12 Correct 2 ms 8796 KB Output is correct
13 Correct 2 ms 8796 KB Output is correct
14 Correct 2 ms 8792 KB Output is correct
15 Correct 2 ms 8796 KB Output is correct
16 Correct 2 ms 8796 KB Output is correct
17 Correct 2 ms 8796 KB Output is correct
18 Correct 2 ms 8796 KB Output is correct
19 Correct 2 ms 8796 KB Output is correct
20 Correct 2 ms 8616 KB Output is correct
21 Correct 3 ms 8796 KB Output is correct
22 Correct 2 ms 8796 KB Output is correct
23 Correct 3 ms 8796 KB Output is correct
24 Correct 2 ms 8796 KB Output is correct
25 Correct 3 ms 8796 KB Output is correct
26 Correct 2 ms 8796 KB Output is correct
27 Correct 2 ms 8796 KB Output is correct
28 Correct 3 ms 8796 KB Output is correct
29 Correct 4 ms 8796 KB Output is correct
30 Correct 3 ms 8796 KB Output is correct
31 Correct 3 ms 8796 KB Output is correct
32 Correct 4 ms 8796 KB Output is correct
33 Correct 4 ms 8796 KB Output is correct
34 Correct 3 ms 8860 KB Output is correct
35 Correct 3 ms 8796 KB Output is correct
36 Correct 3 ms 8796 KB Output is correct
37 Correct 3 ms 8796 KB Output is correct
38 Correct 3 ms 8796 KB Output is correct
39 Correct 173 ms 16212 KB Output is correct
40 Correct 176 ms 16408 KB Output is correct
41 Correct 198 ms 16212 KB Output is correct
42 Correct 174 ms 16468 KB Output is correct
43 Correct 80 ms 16724 KB Output is correct
44 Correct 62 ms 16864 KB Output is correct
45 Correct 124 ms 19320 KB Output is correct
46 Correct 86 ms 22092 KB Output is correct
47 Correct 170 ms 22244 KB Output is correct
48 Correct 206 ms 33596 KB Output is correct
49 Correct 170 ms 32680 KB Output is correct
50 Correct 182 ms 22096 KB Output is correct
51 Correct 160 ms 22096 KB Output is correct
52 Correct 184 ms 22168 KB Output is correct
53 Correct 241 ms 21344 KB Output is correct
54 Correct 108 ms 22016 KB Output is correct
55 Correct 26 ms 9564 KB Output is correct
56 Correct 14 ms 9560 KB Output is correct
57 Correct 145 ms 16636 KB Output is correct
58 Correct 39 ms 16328 KB Output is correct
59 Correct 328 ms 28756 KB Output is correct
60 Correct 954 ms 49192 KB Output is correct
61 Correct 255 ms 22640 KB Output is correct
62 Correct 310 ms 22612 KB Output is correct
63 Correct 318 ms 22684 KB Output is correct
64 Correct 1037 ms 31700 KB Output is correct
65 Correct 110 ms 23120 KB Output is correct
66 Correct 573 ms 30948 KB Output is correct
67 Correct 92 ms 22904 KB Output is correct
68 Correct 378 ms 30288 KB Output is correct
69 Correct 412 ms 30036 KB Output is correct
70 Correct 386 ms 29520 KB Output is correct