답안 #1099619

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1099619 2024-10-11T20:30:08 Z MrNanama 경주 (Race) (IOI11_race) C++17
100 / 100
395 ms 127364 KB
#include <bits/stdc++.h>
#define pb push_back
#define fi first
#define se second

using namespace std;
using ll = long long;

template <typename T> ostream& operator<<(ostream& os, const vector<T>& vec){for (auto itr : vec){os << itr << " ";} return os;}

ll n,k,ans;

vector<vector<pair<ll,ll>>> neigh;
vector<pair<ll,ll>> parent;
vector<vector<pair<ll,ll>>> kids;
vector<ll> depth_d;
vector<ll> depth_r;

vector<set<pair<ll,ll>>> info;

void make_tree(ll v, ll e, ll come_w, ll d_r, ll d_d){
	parent[v] = {e, come_w};
	depth_r[v] = d_r;
	depth_d[v] = d_d;


	for(pair<ll,ll> p:neigh[v]){
		if(p.fi == e){continue;}

		kids[v].pb({p.fi, p.se});
		make_tree(p.fi, v, p.se, d_r+p.se, d_d+1);
	}
}

pair<ll,ll> get_min_dist(set<pair<ll,ll>>& sing_info, ll v){
	auto at = sing_info.lower_bound({v,-LLONG_MAX});

	if(at == sing_info.end() || (*at).fi != v){return {LLONG_MAX,LLONG_MAX};}

	return *at;
}

void dfs(ll v){
	info[v].insert(make_pair(depth_r[v], depth_d[v]));

	for(pair<ll,ll> p:kids[v]){
		dfs(p.fi);
	}

	for(pair<ll,ll> p:kids[v]){
		ll go = p.fi;
		if(info[go].size() > info[v].size()){swap(info[go], info[v]);}

		for(pair<ll,ll> ele:info[go]){
			pair<ll,ll> res = get_min_dist(info[v], k-(ele.fi-depth_r[v])+depth_r[v]);
			if(res.se == LLONG_MAX){continue;}

			ans = min<ll>(ans, res.se-depth_d[v]+ele.se-depth_d[v]);
		}

		for(pair<ll,ll> ele:info[go]){info[v].insert(ele);}
	}
}

//template <size_t N_size>
int best_path(int N_inp, int K_inp, int H_inp[][2], int L_inp[]){
	n = N_inp;
	k = K_inp;
	ans = LLONG_MAX;

	neigh.resize(n);
	parent.resize(n);
	kids.resize(n);

	depth_d.resize(n);
	depth_r.resize(n);
	info.resize(n);

	for(ll i=0; i<n-1; i++){
		ll n1 = H_inp[i][0];
		ll n2 = H_inp[i][1];
		ll w = L_inp[i];

		neigh[n1].pb({n2,w});
		neigh[n2].pb({n1,w});
	}

	make_tree(0, -1, LLONG_MAX, 0, 0);

	dfs(0);

	if(ans == LLONG_MAX){return -1;}
	else{return ans;}
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 604 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 448 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 1 ms 444 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 604 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 448 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 1 ms 444 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 1 ms 860 KB Output is correct
22 Correct 1 ms 860 KB Output is correct
23 Correct 2 ms 860 KB Output is correct
24 Correct 1 ms 860 KB Output is correct
25 Correct 1 ms 860 KB Output is correct
26 Correct 1 ms 860 KB Output is correct
27 Correct 1 ms 604 KB Output is correct
28 Correct 1 ms 860 KB Output is correct
29 Correct 1 ms 860 KB Output is correct
30 Correct 1 ms 860 KB Output is correct
31 Correct 1 ms 860 KB Output is correct
32 Correct 1 ms 860 KB Output is correct
33 Correct 2 ms 860 KB Output is correct
34 Correct 1 ms 604 KB Output is correct
35 Correct 1 ms 696 KB Output is correct
36 Correct 1 ms 604 KB Output is correct
37 Correct 1 ms 604 KB Output is correct
38 Correct 1 ms 860 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 604 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 448 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 1 ms 444 KB Output is correct
19 Correct 121 ms 43604 KB Output is correct
20 Correct 128 ms 43616 KB Output is correct
21 Correct 117 ms 42836 KB Output is correct
22 Correct 110 ms 41348 KB Output is correct
23 Correct 135 ms 55888 KB Output is correct
24 Correct 112 ms 41512 KB Output is correct
25 Correct 120 ms 46160 KB Output is correct
26 Correct 71 ms 49836 KB Output is correct
27 Correct 165 ms 68688 KB Output is correct
28 Correct 263 ms 99584 KB Output is correct
29 Correct 268 ms 98384 KB Output is correct
30 Correct 168 ms 68836 KB Output is correct
31 Correct 157 ms 68688 KB Output is correct
32 Correct 207 ms 68692 KB Output is correct
33 Correct 195 ms 71344 KB Output is correct
34 Correct 262 ms 104256 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 604 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 448 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 1 ms 444 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 1 ms 860 KB Output is correct
22 Correct 1 ms 860 KB Output is correct
23 Correct 2 ms 860 KB Output is correct
24 Correct 1 ms 860 KB Output is correct
25 Correct 1 ms 860 KB Output is correct
26 Correct 1 ms 860 KB Output is correct
27 Correct 1 ms 604 KB Output is correct
28 Correct 1 ms 860 KB Output is correct
29 Correct 1 ms 860 KB Output is correct
30 Correct 1 ms 860 KB Output is correct
31 Correct 1 ms 860 KB Output is correct
32 Correct 1 ms 860 KB Output is correct
33 Correct 2 ms 860 KB Output is correct
34 Correct 1 ms 604 KB Output is correct
35 Correct 1 ms 696 KB Output is correct
36 Correct 1 ms 604 KB Output is correct
37 Correct 1 ms 604 KB Output is correct
38 Correct 1 ms 860 KB Output is correct
39 Correct 121 ms 43604 KB Output is correct
40 Correct 128 ms 43616 KB Output is correct
41 Correct 117 ms 42836 KB Output is correct
42 Correct 110 ms 41348 KB Output is correct
43 Correct 135 ms 55888 KB Output is correct
44 Correct 112 ms 41512 KB Output is correct
45 Correct 120 ms 46160 KB Output is correct
46 Correct 71 ms 49836 KB Output is correct
47 Correct 165 ms 68688 KB Output is correct
48 Correct 263 ms 99584 KB Output is correct
49 Correct 268 ms 98384 KB Output is correct
50 Correct 168 ms 68836 KB Output is correct
51 Correct 157 ms 68688 KB Output is correct
52 Correct 207 ms 68692 KB Output is correct
53 Correct 195 ms 71344 KB Output is correct
54 Correct 262 ms 104256 KB Output is correct
55 Correct 13 ms 5380 KB Output is correct
56 Correct 10 ms 4188 KB Output is correct
57 Correct 65 ms 38136 KB Output is correct
58 Correct 43 ms 27716 KB Output is correct
59 Correct 70 ms 49744 KB Output is correct
60 Correct 247 ms 98640 KB Output is correct
61 Correct 195 ms 74556 KB Output is correct
62 Correct 169 ms 68800 KB Output is correct
63 Correct 210 ms 68688 KB Output is correct
64 Correct 395 ms 127364 KB Output is correct
65 Correct 394 ms 118680 KB Output is correct
66 Correct 301 ms 95968 KB Output is correct
67 Correct 181 ms 56708 KB Output is correct
68 Correct 280 ms 83024 KB Output is correct
69 Correct 293 ms 88400 KB Output is correct
70 Correct 241 ms 79184 KB Output is correct