Submission #349765

# Submission time Handle Problem Language Result Execution time Memory
349765 2021-01-18T10:32:30 Z pavement Race (IOI11_race) C++17
100 / 100
524 ms 146028 KB
#include "race.h"
#include <bits/stdc++.h>
using namespace std;
 
int _K, ans = 1e9, dist[1000005], dep[1000005];
vector<pair<int, int> > adj[1000005];
set<pair<int, int> > S[1000005];
 
void dfs(int n, int e = -1) {
	S[n].emplace(dist[n], dep[n]);
	for (auto u : adj[n]) {
		if (u.first != e) {
			dist[u.first] = dist[n] + u.second;
			dep[u.first] = dep[n] + 1;
			dfs(u.first, n);
			if (S[n].size() < S[u.first].size()) swap(S[n], S[u.first]);
			for (auto i : S[u.first]) {
				auto it = S[n].lower_bound(make_pair(_K - i.first + 2 * dist[n], 0));
				if (it != S[n].end() && it->first + i.first - 2 * dist[n] == _K) ans = min(ans, it->second + i.second - 2 * dep[n]);
			}
			for (auto i : S[u.first]) S[n].insert(i);
		}
	}
}
 
int best_path(int N, int K, int H[][2], int L[]) {
	_K = K;
	for (int i = 0; i < N - 1; i++) {
		adj[H[i][0]].emplace_back(H[i][1], L[i]);
		adj[H[i][1]].emplace_back(H[i][0], L[i]);
	}
	dfs(0);
	return (ans == 1e9 ? -1 : ans);
}
# Verdict Execution time Memory Grader output
1 Correct 47 ms 70764 KB Output is correct
2 Correct 47 ms 70764 KB Output is correct
3 Correct 48 ms 70764 KB Output is correct
4 Correct 48 ms 70764 KB Output is correct
5 Correct 48 ms 70764 KB Output is correct
6 Correct 48 ms 70764 KB Output is correct
7 Correct 49 ms 70764 KB Output is correct
8 Correct 48 ms 70764 KB Output is correct
9 Correct 48 ms 70764 KB Output is correct
10 Correct 48 ms 70764 KB Output is correct
11 Correct 47 ms 70764 KB Output is correct
12 Correct 48 ms 70764 KB Output is correct
13 Correct 48 ms 70848 KB Output is correct
14 Correct 47 ms 70764 KB Output is correct
15 Correct 48 ms 70892 KB Output is correct
16 Correct 48 ms 70836 KB Output is correct
17 Correct 48 ms 70764 KB Output is correct
18 Correct 48 ms 70764 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 47 ms 70764 KB Output is correct
2 Correct 47 ms 70764 KB Output is correct
3 Correct 48 ms 70764 KB Output is correct
4 Correct 48 ms 70764 KB Output is correct
5 Correct 48 ms 70764 KB Output is correct
6 Correct 48 ms 70764 KB Output is correct
7 Correct 49 ms 70764 KB Output is correct
8 Correct 48 ms 70764 KB Output is correct
9 Correct 48 ms 70764 KB Output is correct
10 Correct 48 ms 70764 KB Output is correct
11 Correct 47 ms 70764 KB Output is correct
12 Correct 48 ms 70764 KB Output is correct
13 Correct 48 ms 70848 KB Output is correct
14 Correct 47 ms 70764 KB Output is correct
15 Correct 48 ms 70892 KB Output is correct
16 Correct 48 ms 70836 KB Output is correct
17 Correct 48 ms 70764 KB Output is correct
18 Correct 48 ms 70764 KB Output is correct
19 Correct 48 ms 70764 KB Output is correct
20 Correct 47 ms 70764 KB Output is correct
21 Correct 50 ms 71040 KB Output is correct
22 Correct 49 ms 71020 KB Output is correct
23 Correct 50 ms 71020 KB Output is correct
24 Correct 49 ms 71212 KB Output is correct
25 Correct 49 ms 71020 KB Output is correct
26 Correct 48 ms 71020 KB Output is correct
27 Correct 48 ms 70892 KB Output is correct
28 Correct 49 ms 71020 KB Output is correct
29 Correct 50 ms 71020 KB Output is correct
30 Correct 49 ms 71020 KB Output is correct
31 Correct 49 ms 71020 KB Output is correct
32 Correct 49 ms 71020 KB Output is correct
33 Correct 49 ms 71020 KB Output is correct
34 Correct 49 ms 71020 KB Output is correct
35 Correct 48 ms 71020 KB Output is correct
36 Correct 48 ms 71020 KB Output is correct
37 Correct 54 ms 71020 KB Output is correct
38 Correct 48 ms 71020 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 47 ms 70764 KB Output is correct
2 Correct 47 ms 70764 KB Output is correct
3 Correct 48 ms 70764 KB Output is correct
4 Correct 48 ms 70764 KB Output is correct
5 Correct 48 ms 70764 KB Output is correct
6 Correct 48 ms 70764 KB Output is correct
7 Correct 49 ms 70764 KB Output is correct
8 Correct 48 ms 70764 KB Output is correct
9 Correct 48 ms 70764 KB Output is correct
10 Correct 48 ms 70764 KB Output is correct
11 Correct 47 ms 70764 KB Output is correct
12 Correct 48 ms 70764 KB Output is correct
13 Correct 48 ms 70848 KB Output is correct
14 Correct 47 ms 70764 KB Output is correct
15 Correct 48 ms 70892 KB Output is correct
16 Correct 48 ms 70836 KB Output is correct
17 Correct 48 ms 70764 KB Output is correct
18 Correct 48 ms 70764 KB Output is correct
19 Correct 198 ms 93164 KB Output is correct
20 Correct 199 ms 93292 KB Output is correct
21 Correct 195 ms 92640 KB Output is correct
22 Correct 195 ms 91500 KB Output is correct
23 Correct 229 ms 102508 KB Output is correct
24 Correct 184 ms 92396 KB Output is correct
25 Correct 190 ms 96236 KB Output is correct
26 Correct 131 ms 100716 KB Output is correct
27 Correct 287 ms 101868 KB Output is correct
28 Correct 339 ms 130924 KB Output is correct
29 Correct 343 ms 129580 KB Output is correct
30 Correct 295 ms 101928 KB Output is correct
31 Correct 287 ms 101740 KB Output is correct
32 Correct 376 ms 101868 KB Output is correct
33 Correct 293 ms 102892 KB Output is correct
34 Correct 397 ms 127852 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 47 ms 70764 KB Output is correct
2 Correct 47 ms 70764 KB Output is correct
3 Correct 48 ms 70764 KB Output is correct
4 Correct 48 ms 70764 KB Output is correct
5 Correct 48 ms 70764 KB Output is correct
6 Correct 48 ms 70764 KB Output is correct
7 Correct 49 ms 70764 KB Output is correct
8 Correct 48 ms 70764 KB Output is correct
9 Correct 48 ms 70764 KB Output is correct
10 Correct 48 ms 70764 KB Output is correct
11 Correct 47 ms 70764 KB Output is correct
12 Correct 48 ms 70764 KB Output is correct
13 Correct 48 ms 70848 KB Output is correct
14 Correct 47 ms 70764 KB Output is correct
15 Correct 48 ms 70892 KB Output is correct
16 Correct 48 ms 70836 KB Output is correct
17 Correct 48 ms 70764 KB Output is correct
18 Correct 48 ms 70764 KB Output is correct
19 Correct 48 ms 70764 KB Output is correct
20 Correct 47 ms 70764 KB Output is correct
21 Correct 50 ms 71040 KB Output is correct
22 Correct 49 ms 71020 KB Output is correct
23 Correct 50 ms 71020 KB Output is correct
24 Correct 49 ms 71212 KB Output is correct
25 Correct 49 ms 71020 KB Output is correct
26 Correct 48 ms 71020 KB Output is correct
27 Correct 48 ms 70892 KB Output is correct
28 Correct 49 ms 71020 KB Output is correct
29 Correct 50 ms 71020 KB Output is correct
30 Correct 49 ms 71020 KB Output is correct
31 Correct 49 ms 71020 KB Output is correct
32 Correct 49 ms 71020 KB Output is correct
33 Correct 49 ms 71020 KB Output is correct
34 Correct 49 ms 71020 KB Output is correct
35 Correct 48 ms 71020 KB Output is correct
36 Correct 48 ms 71020 KB Output is correct
37 Correct 54 ms 71020 KB Output is correct
38 Correct 48 ms 71020 KB Output is correct
39 Correct 198 ms 93164 KB Output is correct
40 Correct 199 ms 93292 KB Output is correct
41 Correct 195 ms 92640 KB Output is correct
42 Correct 195 ms 91500 KB Output is correct
43 Correct 229 ms 102508 KB Output is correct
44 Correct 184 ms 92396 KB Output is correct
45 Correct 190 ms 96236 KB Output is correct
46 Correct 131 ms 100716 KB Output is correct
47 Correct 287 ms 101868 KB Output is correct
48 Correct 339 ms 130924 KB Output is correct
49 Correct 343 ms 129580 KB Output is correct
50 Correct 295 ms 101928 KB Output is correct
51 Correct 287 ms 101740 KB Output is correct
52 Correct 376 ms 101868 KB Output is correct
53 Correct 293 ms 102892 KB Output is correct
54 Correct 397 ms 127852 KB Output is correct
55 Correct 61 ms 73580 KB Output is correct
56 Correct 57 ms 72684 KB Output is correct
57 Correct 134 ms 89196 KB Output is correct
58 Correct 101 ms 82400 KB Output is correct
59 Correct 130 ms 100716 KB Output is correct
60 Correct 326 ms 129900 KB Output is correct
61 Correct 323 ms 106220 KB Output is correct
62 Correct 288 ms 101996 KB Output is correct
63 Correct 364 ms 101996 KB Output is correct
64 Correct 524 ms 146028 KB Output is correct
65 Correct 518 ms 139884 KB Output is correct
66 Correct 346 ms 126572 KB Output is correct
67 Correct 246 ms 95708 KB Output is correct
68 Correct 454 ms 113772 KB Output is correct
69 Correct 485 ms 117996 KB Output is correct
70 Correct 430 ms 111852 KB Output is correct