답안 #1056205

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1056205 2024-08-13T08:14:05 Z vjudge1 경주 (Race) (IOI11_race) C++17
100 / 100
214 ms 32032 KB
#include "race.h"
#include <bits/stdc++.h>
using namespace std;
 
vector<pair<int,int>> v[200005];
int vis[200005],sub[200005],mpp[1000005];
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[k-der]!=-1)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[der]==-1)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 sifirla(int node,int ata,int der){
	if(der>k)return ;
	mpp[der]=-1;
	for(auto go:v[node]){
		if(go.fi==ata || vis[go.fi])continue;
		sifirla(go.fi,node,der+go.se);
	}
}
 
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);
	}
	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;
}
 
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 14168 KB Output is correct
2 Correct 2 ms 14452 KB Output is correct
3 Correct 2 ms 14248 KB Output is correct
4 Correct 2 ms 14172 KB Output is correct
5 Correct 2 ms 14172 KB Output is correct
6 Correct 2 ms 14172 KB Output is correct
7 Correct 2 ms 14172 KB Output is correct
8 Correct 2 ms 14172 KB Output is correct
9 Correct 2 ms 14172 KB Output is correct
10 Correct 2 ms 14172 KB Output is correct
11 Correct 2 ms 14172 KB Output is correct
12 Correct 2 ms 14172 KB Output is correct
13 Correct 2 ms 14172 KB Output is correct
14 Correct 2 ms 14172 KB Output is correct
15 Correct 2 ms 14260 KB Output is correct
16 Correct 2 ms 14244 KB Output is correct
17 Correct 2 ms 14248 KB Output is correct
18 Correct 2 ms 14172 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 14168 KB Output is correct
2 Correct 2 ms 14452 KB Output is correct
3 Correct 2 ms 14248 KB Output is correct
4 Correct 2 ms 14172 KB Output is correct
5 Correct 2 ms 14172 KB Output is correct
6 Correct 2 ms 14172 KB Output is correct
7 Correct 2 ms 14172 KB Output is correct
8 Correct 2 ms 14172 KB Output is correct
9 Correct 2 ms 14172 KB Output is correct
10 Correct 2 ms 14172 KB Output is correct
11 Correct 2 ms 14172 KB Output is correct
12 Correct 2 ms 14172 KB Output is correct
13 Correct 2 ms 14172 KB Output is correct
14 Correct 2 ms 14172 KB Output is correct
15 Correct 2 ms 14260 KB Output is correct
16 Correct 2 ms 14244 KB Output is correct
17 Correct 2 ms 14248 KB Output is correct
18 Correct 2 ms 14172 KB Output is correct
19 Correct 2 ms 14172 KB Output is correct
20 Correct 2 ms 14172 KB Output is correct
21 Correct 2 ms 14172 KB Output is correct
22 Correct 3 ms 14172 KB Output is correct
23 Correct 2 ms 14216 KB Output is correct
24 Correct 2 ms 14316 KB Output is correct
25 Correct 2 ms 14172 KB Output is correct
26 Correct 2 ms 14264 KB Output is correct
27 Correct 2 ms 14424 KB Output is correct
28 Correct 2 ms 14172 KB Output is correct
29 Correct 2 ms 14172 KB Output is correct
30 Correct 2 ms 14168 KB Output is correct
31 Correct 2 ms 14260 KB Output is correct
32 Correct 3 ms 14172 KB Output is correct
33 Correct 2 ms 14168 KB Output is correct
34 Correct 3 ms 14172 KB Output is correct
35 Correct 2 ms 14172 KB Output is correct
36 Correct 2 ms 14172 KB Output is correct
37 Correct 2 ms 14264 KB Output is correct
38 Correct 2 ms 14172 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 14168 KB Output is correct
2 Correct 2 ms 14452 KB Output is correct
3 Correct 2 ms 14248 KB Output is correct
4 Correct 2 ms 14172 KB Output is correct
5 Correct 2 ms 14172 KB Output is correct
6 Correct 2 ms 14172 KB Output is correct
7 Correct 2 ms 14172 KB Output is correct
8 Correct 2 ms 14172 KB Output is correct
9 Correct 2 ms 14172 KB Output is correct
10 Correct 2 ms 14172 KB Output is correct
11 Correct 2 ms 14172 KB Output is correct
12 Correct 2 ms 14172 KB Output is correct
13 Correct 2 ms 14172 KB Output is correct
14 Correct 2 ms 14172 KB Output is correct
15 Correct 2 ms 14260 KB Output is correct
16 Correct 2 ms 14244 KB Output is correct
17 Correct 2 ms 14248 KB Output is correct
18 Correct 2 ms 14172 KB Output is correct
19 Correct 74 ms 21340 KB Output is correct
20 Correct 69 ms 21332 KB Output is correct
21 Correct 76 ms 21332 KB Output is correct
22 Correct 65 ms 21596 KB Output is correct
23 Correct 31 ms 21596 KB Output is correct
24 Correct 28 ms 21500 KB Output is correct
25 Correct 62 ms 22420 KB Output is correct
26 Correct 50 ms 23900 KB Output is correct
27 Correct 78 ms 26960 KB Output is correct
28 Correct 107 ms 32032 KB Output is correct
29 Correct 106 ms 31420 KB Output is correct
30 Correct 77 ms 26708 KB Output is correct
31 Correct 89 ms 26704 KB Output is correct
32 Correct 84 ms 26776 KB Output is correct
33 Correct 103 ms 25432 KB Output is correct
34 Correct 81 ms 26596 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 14168 KB Output is correct
2 Correct 2 ms 14452 KB Output is correct
3 Correct 2 ms 14248 KB Output is correct
4 Correct 2 ms 14172 KB Output is correct
5 Correct 2 ms 14172 KB Output is correct
6 Correct 2 ms 14172 KB Output is correct
7 Correct 2 ms 14172 KB Output is correct
8 Correct 2 ms 14172 KB Output is correct
9 Correct 2 ms 14172 KB Output is correct
10 Correct 2 ms 14172 KB Output is correct
11 Correct 2 ms 14172 KB Output is correct
12 Correct 2 ms 14172 KB Output is correct
13 Correct 2 ms 14172 KB Output is correct
14 Correct 2 ms 14172 KB Output is correct
15 Correct 2 ms 14260 KB Output is correct
16 Correct 2 ms 14244 KB Output is correct
17 Correct 2 ms 14248 KB Output is correct
18 Correct 2 ms 14172 KB Output is correct
19 Correct 2 ms 14172 KB Output is correct
20 Correct 2 ms 14172 KB Output is correct
21 Correct 2 ms 14172 KB Output is correct
22 Correct 3 ms 14172 KB Output is correct
23 Correct 2 ms 14216 KB Output is correct
24 Correct 2 ms 14316 KB Output is correct
25 Correct 2 ms 14172 KB Output is correct
26 Correct 2 ms 14264 KB Output is correct
27 Correct 2 ms 14424 KB Output is correct
28 Correct 2 ms 14172 KB Output is correct
29 Correct 2 ms 14172 KB Output is correct
30 Correct 2 ms 14168 KB Output is correct
31 Correct 2 ms 14260 KB Output is correct
32 Correct 3 ms 14172 KB Output is correct
33 Correct 2 ms 14168 KB Output is correct
34 Correct 3 ms 14172 KB Output is correct
35 Correct 2 ms 14172 KB Output is correct
36 Correct 2 ms 14172 KB Output is correct
37 Correct 2 ms 14264 KB Output is correct
38 Correct 2 ms 14172 KB Output is correct
39 Correct 74 ms 21340 KB Output is correct
40 Correct 69 ms 21332 KB Output is correct
41 Correct 76 ms 21332 KB Output is correct
42 Correct 65 ms 21596 KB Output is correct
43 Correct 31 ms 21596 KB Output is correct
44 Correct 28 ms 21500 KB Output is correct
45 Correct 62 ms 22420 KB Output is correct
46 Correct 50 ms 23900 KB Output is correct
47 Correct 78 ms 26960 KB Output is correct
48 Correct 107 ms 32032 KB Output is correct
49 Correct 106 ms 31420 KB Output is correct
50 Correct 77 ms 26708 KB Output is correct
51 Correct 89 ms 26704 KB Output is correct
52 Correct 84 ms 26776 KB Output is correct
53 Correct 103 ms 25432 KB Output is correct
54 Correct 81 ms 26596 KB Output is correct
55 Correct 6 ms 14684 KB Output is correct
56 Correct 7 ms 14776 KB Output is correct
57 Correct 34 ms 21532 KB Output is correct
58 Correct 18 ms 21456 KB Output is correct
59 Correct 52 ms 24068 KB Output is correct
60 Correct 214 ms 31568 KB Output is correct
61 Correct 89 ms 26816 KB Output is correct
62 Correct 96 ms 26940 KB Output is correct
63 Correct 113 ms 26964 KB Output is correct
64 Correct 213 ms 27216 KB Output is correct
65 Correct 85 ms 27744 KB Output is correct
66 Correct 165 ms 30556 KB Output is correct
67 Correct 49 ms 27596 KB Output is correct
68 Correct 111 ms 27732 KB Output is correct
69 Correct 103 ms 27732 KB Output is correct
70 Correct 100 ms 27220 KB Output is correct