Submission #1054387

# Submission time Handle Problem Language Result Execution time Memory
1054387 2024-08-12T09:25:18 Z blacktulip Race (IOI11_race) C++17
100 / 100
486 ms 36808 KB
#include "race.h"
#include <bits/stdc++.h>
using namespace std;

vector<pair<int,int>> v[200005];
int vis[200005],sub[200005];
map<int,int> mpp;
int k;
int cev;
#define pb push_back
#define fi first
#define se second

inline void pre(int node,int ata){
	sub[node]=1;
	for(auto go:v[node]){
		if(go.fi==ata || vis[go.fi])continue;
		pre(go.fi,node);
		sub[node]+=sub[go.fi];
	}
}

inline int find_centroid(int node,int ata,int val){
	for(auto go:v[node]){
		if(go.fi==ata || vis[go.fi])continue;
		if(sub[go.fi]>=val/2)return find_centroid(go.fi,node,val);
	}
	return node;
}

inline void check(int node,int ata,int der,int kac){
	if(der>k)return ;
	if(mpp.find(k-der)!=mpp.end())cev=min(cev,mpp[k-der]+kac);
	for(auto go:v[node]){
		if(go.fi==ata || vis[go.fi])continue;
		check(go.fi,node,der+go.se,kac+1);
	}
}

inline void build(int node,int ata,int der,int kac){
	if(der>k)return ;
	if(mpp.find(der)==mpp.end())mpp[der]=kac;
	else mpp[der]=min(mpp[der],kac);
	for(auto go:v[node]){
		if(go.fi==ata || vis[go.fi])continue;
		build(go.fi,node,der+go.se,kac+1);
	}
}

inline void solve(int c){
	pre(c,-1);
	c=find_centroid(c,-1,sub[c]);
	mpp[0]=0;
	for(auto go:v[c]){
		if(vis[go.fi])continue;
		check(go.fi,c,go.se,1);
		build(go.fi,c,go.se,1);
	}
	//~ for(auto go:v[c]){
		//~ if(vis[go.fi])continue;
		//~ sifirla(go.fi,c,go.se);
	//~ }
	mpp.clear();
	vis[c]=1;
	for(auto go:v[c]){
		if(vis[go.fi])continue;
		solve(go.fi);
	}
}

int best_path(int N, int K, int H[][2], int L[]){
	k=K;
	//~ memset(mpp,-1,sizeof(mpp));
	for(int i=0;i<N-1;i++){
		v[H[i][0]].pb({H[i][1],L[i]});
		v[H[i][1]].pb({H[i][0],L[i]});
	}
	cev=N+2;
	solve(0);
	if(cev==N+2)cev=-1;
	return cev;
}

# Verdict Execution time Memory Grader output
1 Correct 1 ms 10332 KB Output is correct
2 Correct 1 ms 10332 KB Output is correct
3 Correct 1 ms 10332 KB Output is correct
4 Correct 1 ms 10332 KB Output is correct
5 Correct 2 ms 10332 KB Output is correct
6 Correct 1 ms 10332 KB Output is correct
7 Correct 1 ms 10332 KB Output is correct
8 Correct 1 ms 10332 KB Output is correct
9 Correct 1 ms 10168 KB Output is correct
10 Correct 1 ms 10332 KB Output is correct
11 Correct 1 ms 10332 KB Output is correct
12 Correct 2 ms 10332 KB Output is correct
13 Correct 1 ms 10100 KB Output is correct
14 Correct 1 ms 10332 KB Output is correct
15 Correct 1 ms 10332 KB Output is correct
16 Correct 1 ms 10332 KB Output is correct
17 Correct 2 ms 10332 KB Output is correct
18 Correct 2 ms 10332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 10332 KB Output is correct
2 Correct 1 ms 10332 KB Output is correct
3 Correct 1 ms 10332 KB Output is correct
4 Correct 1 ms 10332 KB Output is correct
5 Correct 2 ms 10332 KB Output is correct
6 Correct 1 ms 10332 KB Output is correct
7 Correct 1 ms 10332 KB Output is correct
8 Correct 1 ms 10332 KB Output is correct
9 Correct 1 ms 10168 KB Output is correct
10 Correct 1 ms 10332 KB Output is correct
11 Correct 1 ms 10332 KB Output is correct
12 Correct 2 ms 10332 KB Output is correct
13 Correct 1 ms 10100 KB Output is correct
14 Correct 1 ms 10332 KB Output is correct
15 Correct 1 ms 10332 KB Output is correct
16 Correct 1 ms 10332 KB Output is correct
17 Correct 2 ms 10332 KB Output is correct
18 Correct 2 ms 10332 KB Output is correct
19 Correct 1 ms 10340 KB Output is correct
20 Correct 1 ms 10332 KB Output is correct
21 Correct 2 ms 10332 KB Output is correct
22 Correct 2 ms 10332 KB Output is correct
23 Correct 2 ms 10332 KB Output is correct
24 Correct 2 ms 10332 KB Output is correct
25 Correct 3 ms 10332 KB Output is correct
26 Correct 2 ms 10332 KB Output is correct
27 Correct 2 ms 10332 KB Output is correct
28 Correct 2 ms 10336 KB Output is correct
29 Correct 2 ms 10332 KB Output is correct
30 Correct 2 ms 10332 KB Output is correct
31 Correct 3 ms 10328 KB Output is correct
32 Correct 3 ms 10332 KB Output is correct
33 Correct 2 ms 10332 KB Output is correct
34 Correct 2 ms 10332 KB Output is correct
35 Correct 2 ms 10332 KB Output is correct
36 Correct 2 ms 10332 KB Output is correct
37 Correct 2 ms 10332 KB Output is correct
38 Correct 2 ms 10332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 10332 KB Output is correct
2 Correct 1 ms 10332 KB Output is correct
3 Correct 1 ms 10332 KB Output is correct
4 Correct 1 ms 10332 KB Output is correct
5 Correct 2 ms 10332 KB Output is correct
6 Correct 1 ms 10332 KB Output is correct
7 Correct 1 ms 10332 KB Output is correct
8 Correct 1 ms 10332 KB Output is correct
9 Correct 1 ms 10168 KB Output is correct
10 Correct 1 ms 10332 KB Output is correct
11 Correct 1 ms 10332 KB Output is correct
12 Correct 2 ms 10332 KB Output is correct
13 Correct 1 ms 10100 KB Output is correct
14 Correct 1 ms 10332 KB Output is correct
15 Correct 1 ms 10332 KB Output is correct
16 Correct 1 ms 10332 KB Output is correct
17 Correct 2 ms 10332 KB Output is correct
18 Correct 2 ms 10332 KB Output is correct
19 Correct 99 ms 16220 KB Output is correct
20 Correct 97 ms 16216 KB Output is correct
21 Correct 105 ms 16216 KB Output is correct
22 Correct 100 ms 16220 KB Output is correct
23 Correct 38 ms 16472 KB Output is correct
24 Correct 38 ms 16216 KB Output is correct
25 Correct 68 ms 17244 KB Output is correct
26 Correct 58 ms 20316 KB Output is correct
27 Correct 96 ms 20052 KB Output is correct
28 Correct 124 ms 24916 KB Output is correct
29 Correct 114 ms 24400 KB Output is correct
30 Correct 95 ms 20052 KB Output is correct
31 Correct 99 ms 20048 KB Output is correct
32 Correct 111 ms 20092 KB Output is correct
33 Correct 126 ms 18676 KB Output is correct
34 Correct 83 ms 18772 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 10332 KB Output is correct
2 Correct 1 ms 10332 KB Output is correct
3 Correct 1 ms 10332 KB Output is correct
4 Correct 1 ms 10332 KB Output is correct
5 Correct 2 ms 10332 KB Output is correct
6 Correct 1 ms 10332 KB Output is correct
7 Correct 1 ms 10332 KB Output is correct
8 Correct 1 ms 10332 KB Output is correct
9 Correct 1 ms 10168 KB Output is correct
10 Correct 1 ms 10332 KB Output is correct
11 Correct 1 ms 10332 KB Output is correct
12 Correct 2 ms 10332 KB Output is correct
13 Correct 1 ms 10100 KB Output is correct
14 Correct 1 ms 10332 KB Output is correct
15 Correct 1 ms 10332 KB Output is correct
16 Correct 1 ms 10332 KB Output is correct
17 Correct 2 ms 10332 KB Output is correct
18 Correct 2 ms 10332 KB Output is correct
19 Correct 1 ms 10340 KB Output is correct
20 Correct 1 ms 10332 KB Output is correct
21 Correct 2 ms 10332 KB Output is correct
22 Correct 2 ms 10332 KB Output is correct
23 Correct 2 ms 10332 KB Output is correct
24 Correct 2 ms 10332 KB Output is correct
25 Correct 3 ms 10332 KB Output is correct
26 Correct 2 ms 10332 KB Output is correct
27 Correct 2 ms 10332 KB Output is correct
28 Correct 2 ms 10336 KB Output is correct
29 Correct 2 ms 10332 KB Output is correct
30 Correct 2 ms 10332 KB Output is correct
31 Correct 3 ms 10328 KB Output is correct
32 Correct 3 ms 10332 KB Output is correct
33 Correct 2 ms 10332 KB Output is correct
34 Correct 2 ms 10332 KB Output is correct
35 Correct 2 ms 10332 KB Output is correct
36 Correct 2 ms 10332 KB Output is correct
37 Correct 2 ms 10332 KB Output is correct
38 Correct 2 ms 10332 KB Output is correct
39 Correct 99 ms 16220 KB Output is correct
40 Correct 97 ms 16216 KB Output is correct
41 Correct 105 ms 16216 KB Output is correct
42 Correct 100 ms 16220 KB Output is correct
43 Correct 38 ms 16472 KB Output is correct
44 Correct 38 ms 16216 KB Output is correct
45 Correct 68 ms 17244 KB Output is correct
46 Correct 58 ms 20316 KB Output is correct
47 Correct 96 ms 20052 KB Output is correct
48 Correct 124 ms 24916 KB Output is correct
49 Correct 114 ms 24400 KB Output is correct
50 Correct 95 ms 20052 KB Output is correct
51 Correct 99 ms 20048 KB Output is correct
52 Correct 111 ms 20092 KB Output is correct
53 Correct 126 ms 18676 KB Output is correct
54 Correct 83 ms 18772 KB Output is correct
55 Correct 12 ms 10840 KB Output is correct
56 Correct 9 ms 10588 KB Output is correct
57 Correct 62 ms 16456 KB Output is correct
58 Correct 24 ms 16336 KB Output is correct
59 Correct 170 ms 23820 KB Output is correct
60 Correct 473 ms 36808 KB Output is correct
61 Correct 136 ms 20308 KB Output is correct
62 Correct 152 ms 20268 KB Output is correct
63 Correct 170 ms 20048 KB Output is correct
64 Correct 486 ms 24200 KB Output is correct
65 Correct 81 ms 19792 KB Output is correct
66 Correct 284 ms 23640 KB Output is correct
67 Correct 60 ms 20348 KB Output is correct
68 Correct 234 ms 23892 KB Output is correct
69 Correct 213 ms 23820 KB Output is correct
70 Correct 189 ms 23616 KB Output is correct