Submission #470309

# Submission time Handle Problem Language Result Execution time Memory
470309 2021-09-03T13:02:09 Z bedirhan Race (IOI11_race) C++17
100 / 100
583 ms 101520 KB
#include <bits/stdc++.h>
using namespace std;

using ll = long long;
#define all(x) x.begin(), x.end()

int best_path(int n, int k, int h[][2], int l[]){
	vector<vector<array<int, 2>>> adj(n);
	for(int i = 0; i < n - 1; ++i){
		int u = h[i][0], v = h[i][1], w = l[i];
		adj[u].push_back({v, w});
		adj[v].push_back({u, w});
	}
	constexpr int INF = 1e9 + 7;
	ll ans = INF;
	map<ll, ll> mp[n]; 
	function<void(int, int, ll, ll)> dfs = [&](int u, int p, ll dis, ll dep){
		mp[u][dis] = dep;
		for(auto &[v, w] : adj[u]){
			if(v == p) continue;
			dfs(v, u, dis + w, dep + 1);
			if(mp[u].size() < mp[v].size()){
				swap(mp[u], mp[v]);
			}
			for(auto &[ndis, ndep] : mp[v]){
				ll target = k + 2 * dis - ndis;
				if(mp[u].count(target))
					ans = min(ans, mp[u][target] + ndep - 2 * dep);
			}
			for(auto &[ndis, ndep] : mp[v]){
				if(!mp[u].count(ndis)){
					mp[u][ndis] = ndep;
				}else{
					mp[u][ndis] = min(mp[u][ndis], ndep);
				}
			}
		}
	};
	dfs(0, -1, 0, 0);
	if(ans == INF) ans = -1;
	return ans;
}

/*
int main(){
	cin.tie(0)->sync_with_stdio(0);
	int n, k; cin >> n >> k;
	vector<vector<array<int, 2>>> adj(n);
	for(int i = 0; i < n - 1; ++i){
		int u, v, w; cin >> u >> v >> w;
		adj[u].push_back({v, w});
		adj[v].push_back({u, w});
	}
	constexpr int INF = 1e9 + 7;
	ll ans = INF;
	map<ll, ll> mp[n]; 
	function<void(int, int, ll, ll)> dfs = [&](int u, int p, ll dis, ll dep){
		mp[u][dis] = dep;
		for(auto &[v, w] : adj[u]){
			if(v == p) continue;
			dfs(v, u, dis + w, dep + 1);
			if(mp[u].size() < mp[v].size()){
				swap(mp[u], mp[v]);
			}
			for(auto &[ndis, ndep] : mp[v]){
				ll target = k + 2 * dis - ndis;
				if(mp[u].count(target))
					ans = min(ans, mp[u][target] + ndep - 2 * dep);
			}
			for(auto &[ndis, ndep] : mp[v]){
				if(!mp[u].count(ndis)){
					mp[u][ndis] = ndep;
				}else{
					mp[u][ndis] = min(mp[u][ndis], ndep);
				}
			}
		}
	};
	dfs(0, -1, 0, 0);
	if(ans == INF) ans = -1;
	cout << ans << '\n';
}
*/
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 300 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 296 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 300 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 296 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 2 ms 588 KB Output is correct
22 Correct 2 ms 588 KB Output is correct
23 Correct 2 ms 588 KB Output is correct
24 Correct 2 ms 588 KB Output is correct
25 Correct 2 ms 588 KB Output is correct
26 Correct 2 ms 588 KB Output is correct
27 Correct 1 ms 460 KB Output is correct
28 Correct 2 ms 588 KB Output is correct
29 Correct 2 ms 588 KB Output is correct
30 Correct 2 ms 588 KB Output is correct
31 Correct 2 ms 588 KB Output is correct
32 Correct 2 ms 568 KB Output is correct
33 Correct 2 ms 692 KB Output is correct
34 Correct 2 ms 588 KB Output is correct
35 Correct 1 ms 588 KB Output is correct
36 Correct 1 ms 588 KB Output is correct
37 Correct 1 ms 588 KB Output is correct
38 Correct 1 ms 588 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 300 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 296 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 165 ms 29044 KB Output is correct
20 Correct 161 ms 29168 KB Output is correct
21 Correct 158 ms 28888 KB Output is correct
22 Correct 163 ms 28408 KB Output is correct
23 Correct 207 ms 41284 KB Output is correct
24 Correct 165 ms 31848 KB Output is correct
25 Correct 131 ms 28996 KB Output is correct
26 Correct 72 ms 36368 KB Output is correct
27 Correct 232 ms 46120 KB Output is correct
28 Correct 390 ms 85436 KB Output is correct
29 Correct 405 ms 83864 KB Output is correct
30 Correct 242 ms 46236 KB Output is correct
31 Correct 237 ms 46140 KB Output is correct
32 Correct 304 ms 46368 KB Output is correct
33 Correct 314 ms 51272 KB Output is correct
34 Correct 435 ms 83924 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 300 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 296 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 2 ms 588 KB Output is correct
22 Correct 2 ms 588 KB Output is correct
23 Correct 2 ms 588 KB Output is correct
24 Correct 2 ms 588 KB Output is correct
25 Correct 2 ms 588 KB Output is correct
26 Correct 2 ms 588 KB Output is correct
27 Correct 1 ms 460 KB Output is correct
28 Correct 2 ms 588 KB Output is correct
29 Correct 2 ms 588 KB Output is correct
30 Correct 2 ms 588 KB Output is correct
31 Correct 2 ms 588 KB Output is correct
32 Correct 2 ms 568 KB Output is correct
33 Correct 2 ms 692 KB Output is correct
34 Correct 2 ms 588 KB Output is correct
35 Correct 1 ms 588 KB Output is correct
36 Correct 1 ms 588 KB Output is correct
37 Correct 1 ms 588 KB Output is correct
38 Correct 1 ms 588 KB Output is correct
39 Correct 165 ms 29044 KB Output is correct
40 Correct 161 ms 29168 KB Output is correct
41 Correct 158 ms 28888 KB Output is correct
42 Correct 163 ms 28408 KB Output is correct
43 Correct 207 ms 41284 KB Output is correct
44 Correct 165 ms 31848 KB Output is correct
45 Correct 131 ms 28996 KB Output is correct
46 Correct 72 ms 36368 KB Output is correct
47 Correct 232 ms 46120 KB Output is correct
48 Correct 390 ms 85436 KB Output is correct
49 Correct 405 ms 83864 KB Output is correct
50 Correct 242 ms 46236 KB Output is correct
51 Correct 237 ms 46140 KB Output is correct
52 Correct 304 ms 46368 KB Output is correct
53 Correct 314 ms 51272 KB Output is correct
54 Correct 435 ms 83924 KB Output is correct
55 Correct 16 ms 4100 KB Output is correct
56 Correct 10 ms 2764 KB Output is correct
57 Correct 99 ms 26440 KB Output is correct
58 Correct 62 ms 19672 KB Output is correct
59 Correct 119 ms 42732 KB Output is correct
60 Correct 386 ms 84188 KB Output is correct
61 Correct 261 ms 49752 KB Output is correct
62 Correct 220 ms 46276 KB Output is correct
63 Correct 292 ms 46516 KB Output is correct
64 Correct 574 ms 101520 KB Output is correct
65 Correct 583 ms 99620 KB Output is correct
66 Correct 401 ms 80256 KB Output is correct
67 Correct 241 ms 40788 KB Output is correct
68 Correct 422 ms 63000 KB Output is correct
69 Correct 432 ms 68268 KB Output is correct
70 Correct 392 ms 60344 KB Output is correct