Submission #1090127

# Submission time Handle Problem Language Result Execution time Memory
1090127 2024-09-17T18:32:25 Z LilPluton Race (IOI11_race) C++14
100 / 100
386 ms 86128 KB
#include "race.h"
#include <bits/stdc++.h>
using namespace std;

const int sz = 2e5 + 5;
int n, k;
vector<vector<pair<int, int>>> adj(sz);
map<int, int> a[sz];
long long sum[sz], dep[sz], res;

void comp(int u, int p, long long  c, int h) {
	a[u][c] = h;
	sum[u] = c;
	dep[u] = h;
	for (auto n : adj[u]) {
		if (p == n.first) { continue; }
		comp(n.first, u, c + n.second, h + 1);
	}
}

void dfs(int u, int p) {
    long long target = k + 2 * sum[u];
	for (auto n : adj[u]) {
		if (n.first == p) { continue; }
		dfs(n.first, u);
		if (a[n.first].size() > a[u].size()) { swap(a[n.first], a[u]); }
		for (auto i : a[n.first]) {
			if (a[u].find(target - i.first) != a[u].end()) {
				res = min(res, a[u][target - i.first] + i.second - 2 * dep[u]);
			}
		}
		for (auto i : a[n.first]) {
			if (a[u].find(i.first) == a[u].end()) {
				a[u].insert(i);
			} else {
				a[u][i.first] = min(a[u][i.first], i.second);
			}
		}
	}
}

int best_path(int N, int K, int H[][2], int L[]) {
	if (k == 1) { return 0; }
	n = N;
	k = K;
	res = INT_MAX;
	for (int i = 0; i < n - 1; i++) {
		int u = H[i][0];
		int v = H[i][1];
		adj[u].push_back(pair<int,int> (v, L[i]));
		adj[v].push_back(pair<int,int> (u, L[i]));
	}
	comp(0, -1, 0, 0);
	dfs(0, -1);
	return res == INT_MAX ? -1 : res;
}
# Verdict Execution time Memory Grader output
1 Correct 7 ms 14428 KB Output is correct
2 Correct 7 ms 14556 KB Output is correct
3 Correct 8 ms 14428 KB Output is correct
4 Correct 7 ms 14428 KB Output is correct
5 Correct 7 ms 14428 KB Output is correct
6 Correct 7 ms 14368 KB Output is correct
7 Correct 6 ms 14392 KB Output is correct
8 Correct 8 ms 14428 KB Output is correct
9 Correct 8 ms 14428 KB Output is correct
10 Correct 6 ms 14552 KB Output is correct
11 Correct 6 ms 14424 KB Output is correct
12 Correct 6 ms 14428 KB Output is correct
13 Correct 7 ms 14456 KB Output is correct
14 Correct 6 ms 14432 KB Output is correct
15 Correct 8 ms 14480 KB Output is correct
16 Correct 6 ms 14428 KB Output is correct
17 Correct 6 ms 14428 KB Output is correct
18 Correct 7 ms 14432 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 14428 KB Output is correct
2 Correct 7 ms 14556 KB Output is correct
3 Correct 8 ms 14428 KB Output is correct
4 Correct 7 ms 14428 KB Output is correct
5 Correct 7 ms 14428 KB Output is correct
6 Correct 7 ms 14368 KB Output is correct
7 Correct 6 ms 14392 KB Output is correct
8 Correct 8 ms 14428 KB Output is correct
9 Correct 8 ms 14428 KB Output is correct
10 Correct 6 ms 14552 KB Output is correct
11 Correct 6 ms 14424 KB Output is correct
12 Correct 6 ms 14428 KB Output is correct
13 Correct 7 ms 14456 KB Output is correct
14 Correct 6 ms 14432 KB Output is correct
15 Correct 8 ms 14480 KB Output is correct
16 Correct 6 ms 14428 KB Output is correct
17 Correct 6 ms 14428 KB Output is correct
18 Correct 7 ms 14432 KB Output is correct
19 Correct 7 ms 14428 KB Output is correct
20 Correct 7 ms 14424 KB Output is correct
21 Correct 7 ms 14688 KB Output is correct
22 Correct 9 ms 14808 KB Output is correct
23 Correct 8 ms 14740 KB Output is correct
24 Correct 8 ms 14572 KB Output is correct
25 Correct 9 ms 14684 KB Output is correct
26 Correct 10 ms 15012 KB Output is correct
27 Correct 8 ms 14576 KB Output is correct
28 Correct 8 ms 14760 KB Output is correct
29 Correct 7 ms 14684 KB Output is correct
30 Correct 8 ms 14656 KB Output is correct
31 Correct 8 ms 14688 KB Output is correct
32 Correct 8 ms 14812 KB Output is correct
33 Correct 11 ms 14684 KB Output is correct
34 Correct 7 ms 14688 KB Output is correct
35 Correct 7 ms 14684 KB Output is correct
36 Correct 7 ms 14688 KB Output is correct
37 Correct 7 ms 14692 KB Output is correct
38 Correct 7 ms 14696 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 14428 KB Output is correct
2 Correct 7 ms 14556 KB Output is correct
3 Correct 8 ms 14428 KB Output is correct
4 Correct 7 ms 14428 KB Output is correct
5 Correct 7 ms 14428 KB Output is correct
6 Correct 7 ms 14368 KB Output is correct
7 Correct 6 ms 14392 KB Output is correct
8 Correct 8 ms 14428 KB Output is correct
9 Correct 8 ms 14428 KB Output is correct
10 Correct 6 ms 14552 KB Output is correct
11 Correct 6 ms 14424 KB Output is correct
12 Correct 6 ms 14428 KB Output is correct
13 Correct 7 ms 14456 KB Output is correct
14 Correct 6 ms 14432 KB Output is correct
15 Correct 8 ms 14480 KB Output is correct
16 Correct 6 ms 14428 KB Output is correct
17 Correct 6 ms 14428 KB Output is correct
18 Correct 7 ms 14432 KB Output is correct
19 Correct 122 ms 33880 KB Output is correct
20 Correct 107 ms 33948 KB Output is correct
21 Correct 111 ms 33624 KB Output is correct
22 Correct 97 ms 33384 KB Output is correct
23 Correct 124 ms 43156 KB Output is correct
24 Correct 91 ms 35920 KB Output is correct
25 Correct 93 ms 35152 KB Output is correct
26 Correct 48 ms 42064 KB Output is correct
27 Correct 157 ms 44624 KB Output is correct
28 Correct 226 ms 79148 KB Output is correct
29 Correct 224 ms 77712 KB Output is correct
30 Correct 152 ms 44652 KB Output is correct
31 Correct 172 ms 44740 KB Output is correct
32 Correct 255 ms 44924 KB Output is correct
33 Correct 197 ms 48012 KB Output is correct
34 Correct 282 ms 73080 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 14428 KB Output is correct
2 Correct 7 ms 14556 KB Output is correct
3 Correct 8 ms 14428 KB Output is correct
4 Correct 7 ms 14428 KB Output is correct
5 Correct 7 ms 14428 KB Output is correct
6 Correct 7 ms 14368 KB Output is correct
7 Correct 6 ms 14392 KB Output is correct
8 Correct 8 ms 14428 KB Output is correct
9 Correct 8 ms 14428 KB Output is correct
10 Correct 6 ms 14552 KB Output is correct
11 Correct 6 ms 14424 KB Output is correct
12 Correct 6 ms 14428 KB Output is correct
13 Correct 7 ms 14456 KB Output is correct
14 Correct 6 ms 14432 KB Output is correct
15 Correct 8 ms 14480 KB Output is correct
16 Correct 6 ms 14428 KB Output is correct
17 Correct 6 ms 14428 KB Output is correct
18 Correct 7 ms 14432 KB Output is correct
19 Correct 7 ms 14428 KB Output is correct
20 Correct 7 ms 14424 KB Output is correct
21 Correct 7 ms 14688 KB Output is correct
22 Correct 9 ms 14808 KB Output is correct
23 Correct 8 ms 14740 KB Output is correct
24 Correct 8 ms 14572 KB Output is correct
25 Correct 9 ms 14684 KB Output is correct
26 Correct 10 ms 15012 KB Output is correct
27 Correct 8 ms 14576 KB Output is correct
28 Correct 8 ms 14760 KB Output is correct
29 Correct 7 ms 14684 KB Output is correct
30 Correct 8 ms 14656 KB Output is correct
31 Correct 8 ms 14688 KB Output is correct
32 Correct 8 ms 14812 KB Output is correct
33 Correct 11 ms 14684 KB Output is correct
34 Correct 7 ms 14688 KB Output is correct
35 Correct 7 ms 14684 KB Output is correct
36 Correct 7 ms 14688 KB Output is correct
37 Correct 7 ms 14692 KB Output is correct
38 Correct 7 ms 14696 KB Output is correct
39 Correct 122 ms 33880 KB Output is correct
40 Correct 107 ms 33948 KB Output is correct
41 Correct 111 ms 33624 KB Output is correct
42 Correct 97 ms 33384 KB Output is correct
43 Correct 124 ms 43156 KB Output is correct
44 Correct 91 ms 35920 KB Output is correct
45 Correct 93 ms 35152 KB Output is correct
46 Correct 48 ms 42064 KB Output is correct
47 Correct 157 ms 44624 KB Output is correct
48 Correct 226 ms 79148 KB Output is correct
49 Correct 224 ms 77712 KB Output is correct
50 Correct 152 ms 44652 KB Output is correct
51 Correct 172 ms 44740 KB Output is correct
52 Correct 255 ms 44924 KB Output is correct
53 Correct 197 ms 48012 KB Output is correct
54 Correct 282 ms 73080 KB Output is correct
55 Correct 18 ms 17104 KB Output is correct
56 Correct 12 ms 16216 KB Output is correct
57 Correct 50 ms 31876 KB Output is correct
58 Correct 47 ms 26820 KB Output is correct
59 Correct 102 ms 46928 KB Output is correct
60 Correct 235 ms 77936 KB Output is correct
61 Correct 189 ms 47388 KB Output is correct
62 Correct 156 ms 44788 KB Output is correct
63 Correct 269 ms 44884 KB Output is correct
64 Correct 386 ms 86128 KB Output is correct
65 Correct 351 ms 84964 KB Output is correct
66 Correct 234 ms 74092 KB Output is correct
67 Correct 156 ms 40644 KB Output is correct
68 Correct 269 ms 57680 KB Output is correct
69 Correct 343 ms 61360 KB Output is correct
70 Correct 268 ms 55888 KB Output is correct