답안 #738404

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
738404 2023-05-08T16:33:47 Z Baytoro 경주 (Race) (IOI11_race) C++17
100 / 100
434 ms 101492 KB
#include "race.h"
//#include "grader.cpp"
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define fr first
#define sc second
#define all(x) x.begin(),x.end()
const ll NN=2e5+5;
vector<pair<int,int>> g[NN];
ll ans=1e9,k;
map<ll,ll> mp[NN];
void dfs(int x, int p, ll d, int depth){
	mp[x][d]=depth;
	for(auto it: g[x]){
		if(it.fr==p) continue;
		dfs(it.fr,x,d+it.sc,depth+1);
		if(mp[x].size()<mp[it.fr].size()) 
			swap(mp[x],mp[it.fr]);
		for(auto i: mp[it.fr]){
			ll target=k-i.fr+2*d;
			if(mp[x].find(target)!=mp[x].end()){
				ans=min(ans,mp[x][target]+i.sc-2*depth);
			}
		}
		for(auto i: mp[it.fr]){
			if(mp[x].find(i.fr)==mp[x].end()){
				mp[x].insert(i);
			}
			else{
				mp[x][i.fr]=min(mp[x][i.fr],i.sc);
			}
		}
	}
}
int best_path(int N, int K, int H[][2], int L[]){
	k=K;
	ans=N;
	for(int i=0;i<N-1;i++){
		int a=H[i][0],b=H[i][1],c=L[i];
		g[a].pb({b,c});
		g[b].pb({a,c});
	}
	dfs(0,-1,0,0);
	if(ans==N) ans=-1;
	return ans;
}

# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 14420 KB Output is correct
2 Correct 7 ms 14440 KB Output is correct
3 Correct 7 ms 14436 KB Output is correct
4 Correct 9 ms 14420 KB Output is correct
5 Correct 7 ms 14420 KB Output is correct
6 Correct 7 ms 14420 KB Output is correct
7 Correct 8 ms 14348 KB Output is correct
8 Correct 7 ms 14400 KB Output is correct
9 Correct 7 ms 14436 KB Output is correct
10 Correct 7 ms 14400 KB Output is correct
11 Correct 7 ms 14440 KB Output is correct
12 Correct 7 ms 14420 KB Output is correct
13 Correct 7 ms 14420 KB Output is correct
14 Correct 7 ms 14420 KB Output is correct
15 Correct 7 ms 14420 KB Output is correct
16 Correct 8 ms 14420 KB Output is correct
17 Correct 8 ms 14420 KB Output is correct
18 Correct 8 ms 14400 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 14420 KB Output is correct
2 Correct 7 ms 14440 KB Output is correct
3 Correct 7 ms 14436 KB Output is correct
4 Correct 9 ms 14420 KB Output is correct
5 Correct 7 ms 14420 KB Output is correct
6 Correct 7 ms 14420 KB Output is correct
7 Correct 8 ms 14348 KB Output is correct
8 Correct 7 ms 14400 KB Output is correct
9 Correct 7 ms 14436 KB Output is correct
10 Correct 7 ms 14400 KB Output is correct
11 Correct 7 ms 14440 KB Output is correct
12 Correct 7 ms 14420 KB Output is correct
13 Correct 7 ms 14420 KB Output is correct
14 Correct 7 ms 14420 KB Output is correct
15 Correct 7 ms 14420 KB Output is correct
16 Correct 8 ms 14420 KB Output is correct
17 Correct 8 ms 14420 KB Output is correct
18 Correct 8 ms 14400 KB Output is correct
19 Correct 7 ms 14292 KB Output is correct
20 Correct 7 ms 14420 KB Output is correct
21 Correct 8 ms 14532 KB Output is correct
22 Correct 8 ms 14696 KB Output is correct
23 Correct 8 ms 14688 KB Output is correct
24 Correct 11 ms 14676 KB Output is correct
25 Correct 10 ms 14676 KB Output is correct
26 Correct 9 ms 14676 KB Output is correct
27 Correct 8 ms 14548 KB Output is correct
28 Correct 8 ms 14676 KB Output is correct
29 Correct 9 ms 14676 KB Output is correct
30 Correct 8 ms 14596 KB Output is correct
31 Correct 8 ms 14676 KB Output is correct
32 Correct 9 ms 14704 KB Output is correct
33 Correct 8 ms 14668 KB Output is correct
34 Correct 8 ms 14664 KB Output is correct
35 Correct 8 ms 14668 KB Output is correct
36 Correct 10 ms 14536 KB Output is correct
37 Correct 8 ms 14532 KB Output is correct
38 Correct 8 ms 14548 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 14420 KB Output is correct
2 Correct 7 ms 14440 KB Output is correct
3 Correct 7 ms 14436 KB Output is correct
4 Correct 9 ms 14420 KB Output is correct
5 Correct 7 ms 14420 KB Output is correct
6 Correct 7 ms 14420 KB Output is correct
7 Correct 8 ms 14348 KB Output is correct
8 Correct 7 ms 14400 KB Output is correct
9 Correct 7 ms 14436 KB Output is correct
10 Correct 7 ms 14400 KB Output is correct
11 Correct 7 ms 14440 KB Output is correct
12 Correct 7 ms 14420 KB Output is correct
13 Correct 7 ms 14420 KB Output is correct
14 Correct 7 ms 14420 KB Output is correct
15 Correct 7 ms 14420 KB Output is correct
16 Correct 8 ms 14420 KB Output is correct
17 Correct 8 ms 14420 KB Output is correct
18 Correct 8 ms 14400 KB Output is correct
19 Correct 121 ms 36144 KB Output is correct
20 Correct 122 ms 36172 KB Output is correct
21 Correct 133 ms 35936 KB Output is correct
22 Correct 128 ms 35452 KB Output is correct
23 Correct 156 ms 48232 KB Output is correct
24 Correct 128 ms 38944 KB Output is correct
25 Correct 109 ms 36020 KB Output is correct
26 Correct 59 ms 43468 KB Output is correct
27 Correct 188 ms 46328 KB Output is correct
28 Correct 316 ms 85480 KB Output is correct
29 Correct 342 ms 83856 KB Output is correct
30 Correct 241 ms 46308 KB Output is correct
31 Correct 200 ms 46424 KB Output is correct
32 Correct 270 ms 46404 KB Output is correct
33 Correct 241 ms 51228 KB Output is correct
34 Correct 355 ms 84116 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 14420 KB Output is correct
2 Correct 7 ms 14440 KB Output is correct
3 Correct 7 ms 14436 KB Output is correct
4 Correct 9 ms 14420 KB Output is correct
5 Correct 7 ms 14420 KB Output is correct
6 Correct 7 ms 14420 KB Output is correct
7 Correct 8 ms 14348 KB Output is correct
8 Correct 7 ms 14400 KB Output is correct
9 Correct 7 ms 14436 KB Output is correct
10 Correct 7 ms 14400 KB Output is correct
11 Correct 7 ms 14440 KB Output is correct
12 Correct 7 ms 14420 KB Output is correct
13 Correct 7 ms 14420 KB Output is correct
14 Correct 7 ms 14420 KB Output is correct
15 Correct 7 ms 14420 KB Output is correct
16 Correct 8 ms 14420 KB Output is correct
17 Correct 8 ms 14420 KB Output is correct
18 Correct 8 ms 14400 KB Output is correct
19 Correct 7 ms 14292 KB Output is correct
20 Correct 7 ms 14420 KB Output is correct
21 Correct 8 ms 14532 KB Output is correct
22 Correct 8 ms 14696 KB Output is correct
23 Correct 8 ms 14688 KB Output is correct
24 Correct 11 ms 14676 KB Output is correct
25 Correct 10 ms 14676 KB Output is correct
26 Correct 9 ms 14676 KB Output is correct
27 Correct 8 ms 14548 KB Output is correct
28 Correct 8 ms 14676 KB Output is correct
29 Correct 9 ms 14676 KB Output is correct
30 Correct 8 ms 14596 KB Output is correct
31 Correct 8 ms 14676 KB Output is correct
32 Correct 9 ms 14704 KB Output is correct
33 Correct 8 ms 14668 KB Output is correct
34 Correct 8 ms 14664 KB Output is correct
35 Correct 8 ms 14668 KB Output is correct
36 Correct 10 ms 14536 KB Output is correct
37 Correct 8 ms 14532 KB Output is correct
38 Correct 8 ms 14548 KB Output is correct
39 Correct 121 ms 36144 KB Output is correct
40 Correct 122 ms 36172 KB Output is correct
41 Correct 133 ms 35936 KB Output is correct
42 Correct 128 ms 35452 KB Output is correct
43 Correct 156 ms 48232 KB Output is correct
44 Correct 128 ms 38944 KB Output is correct
45 Correct 109 ms 36020 KB Output is correct
46 Correct 59 ms 43468 KB Output is correct
47 Correct 188 ms 46328 KB Output is correct
48 Correct 316 ms 85480 KB Output is correct
49 Correct 342 ms 83856 KB Output is correct
50 Correct 241 ms 46308 KB Output is correct
51 Correct 200 ms 46424 KB Output is correct
52 Correct 270 ms 46404 KB Output is correct
53 Correct 241 ms 51228 KB Output is correct
54 Correct 355 ms 84116 KB Output is correct
55 Correct 20 ms 17484 KB Output is correct
56 Correct 14 ms 16212 KB Output is correct
57 Correct 76 ms 33440 KB Output is correct
58 Correct 54 ms 26768 KB Output is correct
59 Correct 123 ms 49688 KB Output is correct
60 Correct 292 ms 84220 KB Output is correct
61 Correct 261 ms 49760 KB Output is correct
62 Correct 178 ms 46380 KB Output is correct
63 Correct 257 ms 46404 KB Output is correct
64 Correct 434 ms 101492 KB Output is correct
65 Correct 422 ms 99624 KB Output is correct
66 Correct 345 ms 80276 KB Output is correct
67 Correct 169 ms 40728 KB Output is correct
68 Correct 367 ms 63348 KB Output is correct
69 Correct 383 ms 68284 KB Output is correct
70 Correct 357 ms 61268 KB Output is correct