답안 #80180

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
80180 2018-10-19T12:07:54 Z farukkastamonuda 경주 (Race) (IOI11_race) C++14
100 / 100
565 ms 95996 KB
#include "race.h"
#include <bits/stdc++.h>
#define fi first
#define se second
#define lo long long 
#define inf 1000000000
#define md 1000000007
#define li 200005
#define li2 1000005
#define mp make_pair
#define pb push_back
using namespace std;
int n,k,vis[li],sub[li],mark[li2],ans=inf;
vector< pair<int,int> > v[li],vec;
vector<int> sil;
int calc(int node,int ata=-1){
	sub[node]=0;
	for(int i=0;i<(int)v[node].size();i++){
		int go=v[node][i].fi;
		if(vis[go]==0 && go!=ata) sub[node]+=calc(go,node);
	}
	return ++sub[node];
}
int find(int node,int ata,int sz){
	for(int i=0;i<(int)v[node].size();i++){
		int go=v[node][i].fi;
		if(go!=ata && vis[go]==0 && sub[go]>sz/2){
			return find(go,node,sz);
		}
	}
	return node;
}
void dfs(int node,int ata,int val,int st){
	if(val==k) ans=min(ans,st);
	if(val<k){
		ans=min(ans,mark[k-val]+st);
		vec.pb(mp(val,st));
	}
	for(int i=0;i<(int)v[node].size();i++){
		int go=v[node][i].fi;
		if(go!=ata && vis[go]==0) dfs(go,node,val+v[node][i].se,st+1);
	}
}
void solve(int cur=1){
	//printf("*");
	int cen=find(cur,-1,calc(cur));
	sil.clear();
	for(int i=0;i<(int)v[cen].size();i++){
		int go=v[cen][i].fi;
		if(vis[go]==1) continue;
		vec.clear();
		dfs(go,cen,v[cen][i].se,1);
		for(int j=0;j<(int)vec.size();j++){
			mark[vec[j].fi]=min(mark[vec[j].fi],vec[j].se);
			sil.pb(vec[j].fi);
		}
	}
	for(int i=0;i<(int)sil.size();i++){
		mark[sil[i]]=inf;
	}
	vis[cen]=1;
	//sil.clear();
	for(int i=0;i<(int)v[cen].size();i++){
		int git=v[cen][i].fi;
		if(vis[git]==0) solve(git);
	}
}
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;
		int vv=H[i][1]+1;
		int c=L[i];
		v[u].pb(mp(vv,c));
		v[vv].pb(mp(u,c));
	}
	for(int i=0;i<=k;i++) mark[i]=inf;
	solve();
	if(ans>=inf) ans=-1;
	return ans;
}
//~ int main(){
	//~ G[0][0]=0,G[0][1]=1;
	//~ G[1][0]=1,G[1][1]=2;
	//~ G[2][0]=1,G[2][1]=3;
	//~ T[0]=1,T[1]=2,T[2]=4;
	//~ int ty=best_path(4,3,G,T);
	//~ printf("%d\n",ty);
	//~ return 0;
//}

# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 5112 KB Output is correct
2 Correct 6 ms 5220 KB Output is correct
3 Correct 6 ms 5220 KB Output is correct
4 Correct 6 ms 5220 KB Output is correct
5 Correct 6 ms 5220 KB Output is correct
6 Correct 6 ms 5260 KB Output is correct
7 Correct 6 ms 5288 KB Output is correct
8 Correct 6 ms 5288 KB Output is correct
9 Correct 7 ms 5288 KB Output is correct
10 Correct 6 ms 5304 KB Output is correct
11 Correct 6 ms 5304 KB Output is correct
12 Correct 7 ms 5304 KB Output is correct
13 Correct 6 ms 5304 KB Output is correct
14 Correct 6 ms 5304 KB Output is correct
15 Correct 7 ms 5304 KB Output is correct
16 Correct 6 ms 5304 KB Output is correct
17 Correct 6 ms 5304 KB Output is correct
18 Correct 6 ms 5304 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 5112 KB Output is correct
2 Correct 6 ms 5220 KB Output is correct
3 Correct 6 ms 5220 KB Output is correct
4 Correct 6 ms 5220 KB Output is correct
5 Correct 6 ms 5220 KB Output is correct
6 Correct 6 ms 5260 KB Output is correct
7 Correct 6 ms 5288 KB Output is correct
8 Correct 6 ms 5288 KB Output is correct
9 Correct 7 ms 5288 KB Output is correct
10 Correct 6 ms 5304 KB Output is correct
11 Correct 6 ms 5304 KB Output is correct
12 Correct 7 ms 5304 KB Output is correct
13 Correct 6 ms 5304 KB Output is correct
14 Correct 6 ms 5304 KB Output is correct
15 Correct 7 ms 5304 KB Output is correct
16 Correct 6 ms 5304 KB Output is correct
17 Correct 6 ms 5304 KB Output is correct
18 Correct 6 ms 5304 KB Output is correct
19 Correct 6 ms 5304 KB Output is correct
20 Correct 6 ms 5304 KB Output is correct
21 Correct 6 ms 5344 KB Output is correct
22 Correct 10 ms 8928 KB Output is correct
23 Correct 9 ms 8928 KB Output is correct
24 Correct 13 ms 8928 KB Output is correct
25 Correct 9 ms 8928 KB Output is correct
26 Correct 8 ms 8928 KB Output is correct
27 Correct 1 ms 8928 KB Output is correct
28 Correct 7 ms 8928 KB Output is correct
29 Correct 8 ms 8928 KB Output is correct
30 Correct 8 ms 8928 KB Output is correct
31 Correct 9 ms 8928 KB Output is correct
32 Correct 9 ms 8928 KB Output is correct
33 Correct 10 ms 8928 KB Output is correct
34 Correct 8 ms 8928 KB Output is correct
35 Correct 11 ms 8928 KB Output is correct
36 Correct 10 ms 8940 KB Output is correct
37 Correct 9 ms 8940 KB Output is correct
38 Correct 9 ms 8940 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 5112 KB Output is correct
2 Correct 6 ms 5220 KB Output is correct
3 Correct 6 ms 5220 KB Output is correct
4 Correct 6 ms 5220 KB Output is correct
5 Correct 6 ms 5220 KB Output is correct
6 Correct 6 ms 5260 KB Output is correct
7 Correct 6 ms 5288 KB Output is correct
8 Correct 6 ms 5288 KB Output is correct
9 Correct 7 ms 5288 KB Output is correct
10 Correct 6 ms 5304 KB Output is correct
11 Correct 6 ms 5304 KB Output is correct
12 Correct 7 ms 5304 KB Output is correct
13 Correct 6 ms 5304 KB Output is correct
14 Correct 6 ms 5304 KB Output is correct
15 Correct 7 ms 5304 KB Output is correct
16 Correct 6 ms 5304 KB Output is correct
17 Correct 6 ms 5304 KB Output is correct
18 Correct 6 ms 5304 KB Output is correct
19 Correct 154 ms 11116 KB Output is correct
20 Correct 171 ms 12412 KB Output is correct
21 Correct 164 ms 14192 KB Output is correct
22 Correct 143 ms 15856 KB Output is correct
23 Correct 142 ms 16980 KB Output is correct
24 Correct 89 ms 18308 KB Output is correct
25 Correct 184 ms 22684 KB Output is correct
26 Correct 115 ms 25848 KB Output is correct
27 Correct 234 ms 29452 KB Output is correct
28 Correct 486 ms 40608 KB Output is correct
29 Correct 565 ms 43200 KB Output is correct
30 Correct 235 ms 43200 KB Output is correct
31 Correct 299 ms 43200 KB Output is correct
32 Correct 317 ms 44444 KB Output is correct
33 Correct 392 ms 46316 KB Output is correct
34 Correct 361 ms 50104 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 5112 KB Output is correct
2 Correct 6 ms 5220 KB Output is correct
3 Correct 6 ms 5220 KB Output is correct
4 Correct 6 ms 5220 KB Output is correct
5 Correct 6 ms 5220 KB Output is correct
6 Correct 6 ms 5260 KB Output is correct
7 Correct 6 ms 5288 KB Output is correct
8 Correct 6 ms 5288 KB Output is correct
9 Correct 7 ms 5288 KB Output is correct
10 Correct 6 ms 5304 KB Output is correct
11 Correct 6 ms 5304 KB Output is correct
12 Correct 7 ms 5304 KB Output is correct
13 Correct 6 ms 5304 KB Output is correct
14 Correct 6 ms 5304 KB Output is correct
15 Correct 7 ms 5304 KB Output is correct
16 Correct 6 ms 5304 KB Output is correct
17 Correct 6 ms 5304 KB Output is correct
18 Correct 6 ms 5304 KB Output is correct
19 Correct 6 ms 5304 KB Output is correct
20 Correct 6 ms 5304 KB Output is correct
21 Correct 6 ms 5344 KB Output is correct
22 Correct 10 ms 8928 KB Output is correct
23 Correct 9 ms 8928 KB Output is correct
24 Correct 13 ms 8928 KB Output is correct
25 Correct 9 ms 8928 KB Output is correct
26 Correct 8 ms 8928 KB Output is correct
27 Correct 1 ms 8928 KB Output is correct
28 Correct 7 ms 8928 KB Output is correct
29 Correct 8 ms 8928 KB Output is correct
30 Correct 8 ms 8928 KB Output is correct
31 Correct 9 ms 8928 KB Output is correct
32 Correct 9 ms 8928 KB Output is correct
33 Correct 10 ms 8928 KB Output is correct
34 Correct 8 ms 8928 KB Output is correct
35 Correct 11 ms 8928 KB Output is correct
36 Correct 10 ms 8940 KB Output is correct
37 Correct 9 ms 8940 KB Output is correct
38 Correct 9 ms 8940 KB Output is correct
39 Correct 154 ms 11116 KB Output is correct
40 Correct 171 ms 12412 KB Output is correct
41 Correct 164 ms 14192 KB Output is correct
42 Correct 143 ms 15856 KB Output is correct
43 Correct 142 ms 16980 KB Output is correct
44 Correct 89 ms 18308 KB Output is correct
45 Correct 184 ms 22684 KB Output is correct
46 Correct 115 ms 25848 KB Output is correct
47 Correct 234 ms 29452 KB Output is correct
48 Correct 486 ms 40608 KB Output is correct
49 Correct 565 ms 43200 KB Output is correct
50 Correct 235 ms 43200 KB Output is correct
51 Correct 299 ms 43200 KB Output is correct
52 Correct 317 ms 44444 KB Output is correct
53 Correct 392 ms 46316 KB Output is correct
54 Correct 361 ms 50104 KB Output is correct
55 Correct 16 ms 50104 KB Output is correct
56 Correct 17 ms 50104 KB Output is correct
57 Correct 100 ms 50104 KB Output is correct
58 Correct 50 ms 50104 KB Output is correct
59 Correct 160 ms 55260 KB Output is correct
60 Correct 513 ms 71396 KB Output is correct
61 Correct 234 ms 71396 KB Output is correct
62 Correct 237 ms 71396 KB Output is correct
63 Correct 312 ms 72044 KB Output is correct
64 Correct 503 ms 74288 KB Output is correct
65 Correct 371 ms 74644 KB Output is correct
66 Correct 549 ms 88460 KB Output is correct
67 Correct 151 ms 88460 KB Output is correct
68 Correct 333 ms 89432 KB Output is correct
69 Correct 330 ms 93300 KB Output is correct
70 Correct 319 ms 95996 KB Output is correct