Submission #416296

# Submission time Handle Problem Language Result Execution time Memory
416296 2021-06-02T09:30:59 Z DEQK Race (IOI11_race) C++17
43 / 100
380 ms 79992 KB
#include "race.h"
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 500500;
ll ans = 1e9;
ll d[N], K;
ll len[N];
vector<pair<int, int>> g[N];
void calc(int u,int p,ll x = 0) {
	len[u] = x;
	for(auto to : g[u]) if(to.first != p) {
		d[to.first] = d[u] + 1;
		calc(to.first, u, x + to.second);
	}
}
map<ll, ll> dfs(int u,int p) {
	map<ll, ll> own;
	own[len[u]] = d[u];
	for(auto to : g[u]) if(to.first != p) {
		auto x = dfs(to.first, u);
		if(x.size() > own.size()) {
			own.swap(x);
		}
		for(auto it : x) {
			if(own.count(K - it.first + 2 * len[u])) {
				ans = min(ans, own[K - it.first + 2 * len[u]] + it.second - 2 * d[u]);
			}
			if(own.count(it.first)) {
				own[it.first] = min(own[it.first], it.second);
			} else {
				own[it.first] = it.second;
			}
		}
	}
	return own;
}
int best_path(int n, int k, int h[][2], int l[]) {
	K = k;
	for(int i = 0; i < n - 1; i++) {
		ll u = h[i][0],v = h[i][1], w = l[i];
		g[u].push_back({v, w});
		g[v].push_back({u, w});
	}
	calc(0, -1);
	dfs(0, -1);
  	if(ans == 1e9) ans = -1;
	return ans;
}
/*int main() {
	int n, k; cin >> n >> k;
	int h[n - 1][2], l[n - 1];
	for(int i = 0; i < n - 1; ++i) {
		cin >> h[i][0] >> h[i][1];
	}
	for(int i = 0; i < n - 1; ++i) {
		cin >> l[i];
	}
	cout << best_path(n, k, h, l);
}*/
# Verdict Execution time Memory Grader output
1 Correct 7 ms 12108 KB Output is correct
2 Correct 7 ms 12104 KB Output is correct
3 Correct 8 ms 11980 KB Output is correct
4 Correct 8 ms 12108 KB Output is correct
5 Correct 7 ms 11980 KB Output is correct
6 Correct 7 ms 11980 KB Output is correct
7 Correct 8 ms 12080 KB Output is correct
8 Correct 7 ms 11980 KB Output is correct
9 Correct 8 ms 12108 KB Output is correct
10 Correct 8 ms 12108 KB Output is correct
11 Correct 7 ms 12108 KB Output is correct
12 Correct 8 ms 12108 KB Output is correct
13 Correct 8 ms 11980 KB Output is correct
14 Correct 7 ms 12108 KB Output is correct
15 Correct 8 ms 12088 KB Output is correct
16 Correct 8 ms 12024 KB Output is correct
17 Correct 8 ms 12108 KB Output is correct
18 Correct 7 ms 11980 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 12108 KB Output is correct
2 Correct 7 ms 12104 KB Output is correct
3 Correct 8 ms 11980 KB Output is correct
4 Correct 8 ms 12108 KB Output is correct
5 Correct 7 ms 11980 KB Output is correct
6 Correct 7 ms 11980 KB Output is correct
7 Correct 8 ms 12080 KB Output is correct
8 Correct 7 ms 11980 KB Output is correct
9 Correct 8 ms 12108 KB Output is correct
10 Correct 8 ms 12108 KB Output is correct
11 Correct 7 ms 12108 KB Output is correct
12 Correct 8 ms 12108 KB Output is correct
13 Correct 8 ms 11980 KB Output is correct
14 Correct 7 ms 12108 KB Output is correct
15 Correct 8 ms 12088 KB Output is correct
16 Correct 8 ms 12024 KB Output is correct
17 Correct 8 ms 12108 KB Output is correct
18 Correct 7 ms 11980 KB Output is correct
19 Correct 7 ms 11980 KB Output is correct
20 Correct 7 ms 11980 KB Output is correct
21 Correct 9 ms 12108 KB Output is correct
22 Correct 11 ms 12108 KB Output is correct
23 Correct 11 ms 12104 KB Output is correct
24 Correct 10 ms 12108 KB Output is correct
25 Correct 9 ms 12108 KB Output is correct
26 Correct 9 ms 12108 KB Output is correct
27 Correct 8 ms 12108 KB Output is correct
28 Correct 9 ms 12168 KB Output is correct
29 Correct 9 ms 12108 KB Output is correct
30 Correct 10 ms 12212 KB Output is correct
31 Correct 9 ms 12108 KB Output is correct
32 Correct 9 ms 12108 KB Output is correct
33 Correct 9 ms 12108 KB Output is correct
34 Correct 8 ms 12192 KB Output is correct
35 Correct 9 ms 12236 KB Output is correct
36 Correct 9 ms 12236 KB Output is correct
37 Correct 8 ms 12236 KB Output is correct
38 Correct 9 ms 12232 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 12108 KB Output is correct
2 Correct 7 ms 12104 KB Output is correct
3 Correct 8 ms 11980 KB Output is correct
4 Correct 8 ms 12108 KB Output is correct
5 Correct 7 ms 11980 KB Output is correct
6 Correct 7 ms 11980 KB Output is correct
7 Correct 8 ms 12080 KB Output is correct
8 Correct 7 ms 11980 KB Output is correct
9 Correct 8 ms 12108 KB Output is correct
10 Correct 8 ms 12108 KB Output is correct
11 Correct 7 ms 12108 KB Output is correct
12 Correct 8 ms 12108 KB Output is correct
13 Correct 8 ms 11980 KB Output is correct
14 Correct 7 ms 12108 KB Output is correct
15 Correct 8 ms 12088 KB Output is correct
16 Correct 8 ms 12024 KB Output is correct
17 Correct 8 ms 12108 KB Output is correct
18 Correct 7 ms 11980 KB Output is correct
19 Correct 139 ms 18456 KB Output is correct
20 Correct 120 ms 18552 KB Output is correct
21 Correct 130 ms 18484 KB Output is correct
22 Correct 122 ms 18500 KB Output is correct
23 Correct 161 ms 18872 KB Output is correct
24 Correct 114 ms 18628 KB Output is correct
25 Correct 106 ms 33084 KB Output is correct
26 Correct 78 ms 46092 KB Output is correct
27 Correct 223 ms 25420 KB Output is correct
28 Correct 319 ms 79992 KB Output is correct
29 Correct 339 ms 77756 KB Output is correct
30 Correct 219 ms 25436 KB Output is correct
31 Correct 214 ms 25396 KB Output is correct
32 Correct 279 ms 25416 KB Output is correct
33 Correct 244 ms 24900 KB Output is correct
34 Correct 380 ms 37656 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 12108 KB Output is correct
2 Correct 7 ms 12104 KB Output is correct
3 Correct 8 ms 11980 KB Output is correct
4 Correct 8 ms 12108 KB Output is correct
5 Correct 7 ms 11980 KB Output is correct
6 Correct 7 ms 11980 KB Output is correct
7 Correct 8 ms 12080 KB Output is correct
8 Correct 7 ms 11980 KB Output is correct
9 Correct 8 ms 12108 KB Output is correct
10 Correct 8 ms 12108 KB Output is correct
11 Correct 7 ms 12108 KB Output is correct
12 Correct 8 ms 12108 KB Output is correct
13 Correct 8 ms 11980 KB Output is correct
14 Correct 7 ms 12108 KB Output is correct
15 Correct 8 ms 12088 KB Output is correct
16 Correct 8 ms 12024 KB Output is correct
17 Correct 8 ms 12108 KB Output is correct
18 Correct 7 ms 11980 KB Output is correct
19 Correct 7 ms 11980 KB Output is correct
20 Correct 7 ms 11980 KB Output is correct
21 Correct 9 ms 12108 KB Output is correct
22 Correct 11 ms 12108 KB Output is correct
23 Correct 11 ms 12104 KB Output is correct
24 Correct 10 ms 12108 KB Output is correct
25 Correct 9 ms 12108 KB Output is correct
26 Correct 9 ms 12108 KB Output is correct
27 Correct 8 ms 12108 KB Output is correct
28 Correct 9 ms 12168 KB Output is correct
29 Correct 9 ms 12108 KB Output is correct
30 Correct 10 ms 12212 KB Output is correct
31 Correct 9 ms 12108 KB Output is correct
32 Correct 9 ms 12108 KB Output is correct
33 Correct 9 ms 12108 KB Output is correct
34 Correct 8 ms 12192 KB Output is correct
35 Correct 9 ms 12236 KB Output is correct
36 Correct 9 ms 12236 KB Output is correct
37 Correct 8 ms 12236 KB Output is correct
38 Correct 9 ms 12232 KB Output is correct
39 Correct 139 ms 18456 KB Output is correct
40 Correct 120 ms 18552 KB Output is correct
41 Correct 130 ms 18484 KB Output is correct
42 Correct 122 ms 18500 KB Output is correct
43 Correct 161 ms 18872 KB Output is correct
44 Correct 114 ms 18628 KB Output is correct
45 Correct 106 ms 33084 KB Output is correct
46 Correct 78 ms 46092 KB Output is correct
47 Correct 223 ms 25420 KB Output is correct
48 Correct 319 ms 79992 KB Output is correct
49 Correct 339 ms 77756 KB Output is correct
50 Correct 219 ms 25436 KB Output is correct
51 Correct 214 ms 25396 KB Output is correct
52 Correct 279 ms 25416 KB Output is correct
53 Correct 244 ms 24900 KB Output is correct
54 Correct 380 ms 37656 KB Output is correct
55 Correct 21 ms 13084 KB Output is correct
56 Correct 14 ms 12712 KB Output is correct
57 Incorrect 69 ms 18688 KB Output isn't correct
58 Halted 0 ms 0 KB -