답안 #1054388

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1054388 2024-08-12T09:25:48 Z blacktulip 경주 (Race) (IOI11_race) C++17
43 / 100
3000 ms 34100 KB
#include "race.h"
#include <bits/stdc++.h>
using namespace std;

vector<pair<int,int>> v[200005];
int vis[200005],sub[200005];
unordered_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;
}

# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 10328 KB Output is correct
2 Correct 1 ms 10328 KB Output is correct
3 Correct 1 ms 10332 KB Output is correct
4 Correct 1 ms 10332 KB Output is correct
5 Correct 1 ms 10332 KB Output is correct
6 Correct 2 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 10332 KB Output is correct
10 Correct 1 ms 10332 KB Output is correct
11 Correct 2 ms 10332 KB Output is correct
12 Correct 2 ms 10332 KB Output is correct
13 Correct 2 ms 10332 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 1 ms 10332 KB Output is correct
18 Correct 1 ms 10332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 10328 KB Output is correct
2 Correct 1 ms 10328 KB Output is correct
3 Correct 1 ms 10332 KB Output is correct
4 Correct 1 ms 10332 KB Output is correct
5 Correct 1 ms 10332 KB Output is correct
6 Correct 2 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 10332 KB Output is correct
10 Correct 1 ms 10332 KB Output is correct
11 Correct 2 ms 10332 KB Output is correct
12 Correct 2 ms 10332 KB Output is correct
13 Correct 2 ms 10332 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 1 ms 10332 KB Output is correct
18 Correct 1 ms 10332 KB Output is correct
19 Correct 2 ms 10332 KB Output is correct
20 Correct 2 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 10172 KB Output is correct
25 Correct 2 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 3 ms 10332 KB Output is correct
29 Correct 2 ms 10332 KB Output is correct
30 Correct 2 ms 10332 KB Output is correct
31 Correct 2 ms 10332 KB Output is correct
32 Correct 2 ms 10428 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 3 ms 10332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 10328 KB Output is correct
2 Correct 1 ms 10328 KB Output is correct
3 Correct 1 ms 10332 KB Output is correct
4 Correct 1 ms 10332 KB Output is correct
5 Correct 1 ms 10332 KB Output is correct
6 Correct 2 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 10332 KB Output is correct
10 Correct 1 ms 10332 KB Output is correct
11 Correct 2 ms 10332 KB Output is correct
12 Correct 2 ms 10332 KB Output is correct
13 Correct 2 ms 10332 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 1 ms 10332 KB Output is correct
18 Correct 1 ms 10332 KB Output is correct
19 Correct 71 ms 16152 KB Output is correct
20 Correct 74 ms 16224 KB Output is correct
21 Correct 76 ms 16148 KB Output is correct
22 Correct 71 ms 16208 KB Output is correct
23 Correct 35 ms 16476 KB Output is correct
24 Correct 30 ms 16220 KB Output is correct
25 Correct 64 ms 17240 KB Output is correct
26 Correct 53 ms 18772 KB Output is correct
27 Correct 84 ms 20052 KB Output is correct
28 Correct 113 ms 24912 KB Output is correct
29 Correct 115 ms 24404 KB Output is correct
30 Correct 86 ms 20048 KB Output is correct
31 Correct 84 ms 20052 KB Output is correct
32 Correct 98 ms 20088 KB Output is correct
33 Correct 110 ms 18768 KB Output is correct
34 Correct 85 ms 18768 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 10328 KB Output is correct
2 Correct 1 ms 10328 KB Output is correct
3 Correct 1 ms 10332 KB Output is correct
4 Correct 1 ms 10332 KB Output is correct
5 Correct 1 ms 10332 KB Output is correct
6 Correct 2 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 10332 KB Output is correct
10 Correct 1 ms 10332 KB Output is correct
11 Correct 2 ms 10332 KB Output is correct
12 Correct 2 ms 10332 KB Output is correct
13 Correct 2 ms 10332 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 1 ms 10332 KB Output is correct
18 Correct 1 ms 10332 KB Output is correct
19 Correct 2 ms 10332 KB Output is correct
20 Correct 2 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 10172 KB Output is correct
25 Correct 2 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 3 ms 10332 KB Output is correct
29 Correct 2 ms 10332 KB Output is correct
30 Correct 2 ms 10332 KB Output is correct
31 Correct 2 ms 10332 KB Output is correct
32 Correct 2 ms 10428 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 3 ms 10332 KB Output is correct
39 Correct 71 ms 16152 KB Output is correct
40 Correct 74 ms 16224 KB Output is correct
41 Correct 76 ms 16148 KB Output is correct
42 Correct 71 ms 16208 KB Output is correct
43 Correct 35 ms 16476 KB Output is correct
44 Correct 30 ms 16220 KB Output is correct
45 Correct 64 ms 17240 KB Output is correct
46 Correct 53 ms 18772 KB Output is correct
47 Correct 84 ms 20052 KB Output is correct
48 Correct 113 ms 24912 KB Output is correct
49 Correct 115 ms 24404 KB Output is correct
50 Correct 86 ms 20048 KB Output is correct
51 Correct 84 ms 20052 KB Output is correct
52 Correct 98 ms 20088 KB Output is correct
53 Correct 110 ms 18768 KB Output is correct
54 Correct 85 ms 18768 KB Output is correct
55 Correct 11 ms 10844 KB Output is correct
56 Correct 7 ms 10588 KB Output is correct
57 Correct 46 ms 16460 KB Output is correct
58 Correct 21 ms 16336 KB Output is correct
59 Correct 1220 ms 21820 KB Output is correct
60 Execution timed out 3071 ms 34100 KB Time limit exceeded
61 Halted 0 ms 0 KB -