Submission #212650

# Submission time Handle Problem Language Result Execution time Memory
212650 2020-03-23T22:38:10 Z Dan13llljws Race (IOI11_race) C++14
100 / 100
1385 ms 38776 KB
#include <bits/stdc++.h>
using namespace std;
#define INF 0x3f3f3f3f
#define sp ' '
#define nl '\n'
void sc(){}template<class T,class...A>void sc(T&t,A&...a){cin>>t,sc(a...);}
void pr(){}template<class T,class...A>void pr(T t,A...a){cout<<t,pr(a...);}
#define ms(x, y) memset(x, y, sizeof(x))
#define sz(x) (int)(x.size())
#define af(x) x.begin(), x.end()
#define mp make_pair
#define pb push_back
#define f first
#define s second
const int mod = 1e9 + 7, base = 131;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
const int MM = 2e5 + 5;
int M, w[MM], ans = INF; bool vis[MM];
vector<pii> adj[MM];
map<int, int> cnt, tmp;
void get_weight(int src, int par){
	w[src] = 1;
	for (auto v : adj[src]){
		if (v.s == par || vis[v.s]) continue;
		get_weight(v.s, src);
		w[src] += w[v.s];
	}
}
int get_cent(int src, int par, int wt){
	for (auto v : adj[src]){
		if (v.s == par || vis[v.s]) continue;
		if (w[v.s] * 2 > wt) return get_cent(v.s, src, wt);
	}
	return  src;
}
void proc_subtree(int src, int par, int d, int dep){
    if (d > M) return;
	if (d == M) ans = min(ans, dep);
	if (!tmp.count(d)) tmp[d] = dep;
	else tmp[d] = min(tmp[d], dep);
	if (cnt.count(M - d)) ans = min(ans, cnt[M - d] + dep);
	for (auto v : adj[src]){
		if (v.s == par || vis[v.s]) continue;
		proc_subtree(v.s, src, d + v.f, dep + 1);
	}
}
void get_ans(int src){
	cnt.clear(); 
	for (auto v : adj[src]){
		if (vis[v.s]) continue;
		tmp.clear();
		proc_subtree(v.s, src, v.f, 1);
		for (auto m : tmp){
			if (!cnt.count(m.f)) cnt[m.f] = m.s;
			else cnt[m.f] = min(cnt[m.f], m.s);
		}
	}
}
void decomp(int src){
	vis[src] = 1;
	get_ans(src);
	for (auto v : adj[src]){
		if (vis[v.s]) continue;
		get_weight(v.s, src);
		decomp(get_cent(v.s, src, w[v.s]));
	}
}
int best_path(int N, int K, int H[][2], int L[]){
	M = K;
	for (int i = 0; i < N - 1; i++){
		int a = H[i][0], b = H[i][1], c = L[i];
		adj[a].pb(mp(c, b)); adj[b].pb(mp(c, a));
	}
	get_weight(1, 1);
	decomp(get_cent(1, 1, N));
	return ans == INF ? -1 : ans;
}
# Verdict Execution time Memory Grader output
1 Correct 7 ms 5120 KB Output is correct
2 Correct 7 ms 5120 KB Output is correct
3 Correct 7 ms 4992 KB Output is correct
4 Correct 7 ms 5120 KB Output is correct
5 Correct 7 ms 4992 KB Output is correct
6 Correct 7 ms 4992 KB Output is correct
7 Correct 7 ms 4992 KB Output is correct
8 Correct 7 ms 4992 KB Output is correct
9 Correct 7 ms 5120 KB Output is correct
10 Correct 7 ms 4992 KB Output is correct
11 Correct 7 ms 4992 KB Output is correct
12 Correct 7 ms 4992 KB Output is correct
13 Correct 7 ms 4992 KB Output is correct
14 Correct 7 ms 4992 KB Output is correct
15 Correct 7 ms 4992 KB Output is correct
16 Correct 7 ms 4992 KB Output is correct
17 Correct 7 ms 5120 KB Output is correct
18 Correct 7 ms 4992 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 5120 KB Output is correct
2 Correct 7 ms 5120 KB Output is correct
3 Correct 7 ms 4992 KB Output is correct
4 Correct 7 ms 5120 KB Output is correct
5 Correct 7 ms 4992 KB Output is correct
6 Correct 7 ms 4992 KB Output is correct
7 Correct 7 ms 4992 KB Output is correct
8 Correct 7 ms 4992 KB Output is correct
9 Correct 7 ms 5120 KB Output is correct
10 Correct 7 ms 4992 KB Output is correct
11 Correct 7 ms 4992 KB Output is correct
12 Correct 7 ms 4992 KB Output is correct
13 Correct 7 ms 4992 KB Output is correct
14 Correct 7 ms 4992 KB Output is correct
15 Correct 7 ms 4992 KB Output is correct
16 Correct 7 ms 4992 KB Output is correct
17 Correct 7 ms 5120 KB Output is correct
18 Correct 7 ms 4992 KB Output is correct
19 Correct 7 ms 5120 KB Output is correct
20 Correct 7 ms 4992 KB Output is correct
21 Correct 9 ms 5120 KB Output is correct
22 Correct 8 ms 5120 KB Output is correct
23 Correct 8 ms 5120 KB Output is correct
24 Correct 8 ms 5120 KB Output is correct
25 Correct 9 ms 5120 KB Output is correct
26 Correct 8 ms 5120 KB Output is correct
27 Correct 8 ms 5120 KB Output is correct
28 Correct 9 ms 5120 KB Output is correct
29 Correct 9 ms 5120 KB Output is correct
30 Correct 9 ms 5120 KB Output is correct
31 Correct 9 ms 5120 KB Output is correct
32 Correct 9 ms 5120 KB Output is correct
33 Correct 10 ms 5120 KB Output is correct
34 Correct 9 ms 5120 KB Output is correct
35 Correct 9 ms 5120 KB Output is correct
36 Correct 8 ms 5120 KB Output is correct
37 Correct 9 ms 5120 KB Output is correct
38 Correct 9 ms 5168 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 5120 KB Output is correct
2 Correct 7 ms 5120 KB Output is correct
3 Correct 7 ms 4992 KB Output is correct
4 Correct 7 ms 5120 KB Output is correct
5 Correct 7 ms 4992 KB Output is correct
6 Correct 7 ms 4992 KB Output is correct
7 Correct 7 ms 4992 KB Output is correct
8 Correct 7 ms 4992 KB Output is correct
9 Correct 7 ms 5120 KB Output is correct
10 Correct 7 ms 4992 KB Output is correct
11 Correct 7 ms 4992 KB Output is correct
12 Correct 7 ms 4992 KB Output is correct
13 Correct 7 ms 4992 KB Output is correct
14 Correct 7 ms 4992 KB Output is correct
15 Correct 7 ms 4992 KB Output is correct
16 Correct 7 ms 4992 KB Output is correct
17 Correct 7 ms 5120 KB Output is correct
18 Correct 7 ms 4992 KB Output is correct
19 Correct 262 ms 11860 KB Output is correct
20 Correct 259 ms 11896 KB Output is correct
21 Correct 265 ms 11768 KB Output is correct
22 Correct 259 ms 12024 KB Output is correct
23 Correct 113 ms 12152 KB Output is correct
24 Correct 105 ms 11896 KB Output is correct
25 Correct 169 ms 16904 KB Output is correct
26 Correct 119 ms 17400 KB Output is correct
27 Correct 268 ms 18808 KB Output is correct
28 Correct 325 ms 29308 KB Output is correct
29 Correct 313 ms 25208 KB Output is correct
30 Correct 268 ms 18808 KB Output is correct
31 Correct 278 ms 18904 KB Output is correct
32 Correct 287 ms 18936 KB Output is correct
33 Correct 443 ms 17784 KB Output is correct
34 Correct 202 ms 18552 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 5120 KB Output is correct
2 Correct 7 ms 5120 KB Output is correct
3 Correct 7 ms 4992 KB Output is correct
4 Correct 7 ms 5120 KB Output is correct
5 Correct 7 ms 4992 KB Output is correct
6 Correct 7 ms 4992 KB Output is correct
7 Correct 7 ms 4992 KB Output is correct
8 Correct 7 ms 4992 KB Output is correct
9 Correct 7 ms 5120 KB Output is correct
10 Correct 7 ms 4992 KB Output is correct
11 Correct 7 ms 4992 KB Output is correct
12 Correct 7 ms 4992 KB Output is correct
13 Correct 7 ms 4992 KB Output is correct
14 Correct 7 ms 4992 KB Output is correct
15 Correct 7 ms 4992 KB Output is correct
16 Correct 7 ms 4992 KB Output is correct
17 Correct 7 ms 5120 KB Output is correct
18 Correct 7 ms 4992 KB Output is correct
19 Correct 7 ms 5120 KB Output is correct
20 Correct 7 ms 4992 KB Output is correct
21 Correct 9 ms 5120 KB Output is correct
22 Correct 8 ms 5120 KB Output is correct
23 Correct 8 ms 5120 KB Output is correct
24 Correct 8 ms 5120 KB Output is correct
25 Correct 9 ms 5120 KB Output is correct
26 Correct 8 ms 5120 KB Output is correct
27 Correct 8 ms 5120 KB Output is correct
28 Correct 9 ms 5120 KB Output is correct
29 Correct 9 ms 5120 KB Output is correct
30 Correct 9 ms 5120 KB Output is correct
31 Correct 9 ms 5120 KB Output is correct
32 Correct 9 ms 5120 KB Output is correct
33 Correct 10 ms 5120 KB Output is correct
34 Correct 9 ms 5120 KB Output is correct
35 Correct 9 ms 5120 KB Output is correct
36 Correct 8 ms 5120 KB Output is correct
37 Correct 9 ms 5120 KB Output is correct
38 Correct 9 ms 5168 KB Output is correct
39 Correct 262 ms 11860 KB Output is correct
40 Correct 259 ms 11896 KB Output is correct
41 Correct 265 ms 11768 KB Output is correct
42 Correct 259 ms 12024 KB Output is correct
43 Correct 113 ms 12152 KB Output is correct
44 Correct 105 ms 11896 KB Output is correct
45 Correct 169 ms 16904 KB Output is correct
46 Correct 119 ms 17400 KB Output is correct
47 Correct 268 ms 18808 KB Output is correct
48 Correct 325 ms 29308 KB Output is correct
49 Correct 313 ms 25208 KB Output is correct
50 Correct 268 ms 18808 KB Output is correct
51 Correct 278 ms 18904 KB Output is correct
52 Correct 287 ms 18936 KB Output is correct
53 Correct 443 ms 17784 KB Output is correct
54 Correct 202 ms 18552 KB Output is correct
55 Correct 33 ms 5888 KB Output is correct
56 Correct 24 ms 5752 KB Output is correct
57 Correct 193 ms 12132 KB Output is correct
58 Correct 62 ms 11756 KB Output is correct
59 Correct 516 ms 23288 KB Output is correct
60 Correct 1385 ms 38776 KB Output is correct
61 Correct 392 ms 19320 KB Output is correct
62 Correct 414 ms 19064 KB Output is correct
63 Correct 494 ms 19192 KB Output is correct
64 Correct 1374 ms 25848 KB Output is correct
65 Correct 257 ms 19960 KB Output is correct
66 Correct 875 ms 28792 KB Output is correct
67 Correct 155 ms 19620 KB Output is correct
68 Correct 542 ms 23288 KB Output is correct
69 Correct 545 ms 23288 KB Output is correct
70 Correct 512 ms 22520 KB Output is correct