Submission #162557

# Submission time Handle Problem Language Result Execution time Memory
162557 2019-11-08T19:06:41 Z kostia244 Race (IOI11_race) C++14
100 / 100
2458 ms 73196 KB
#define _GLIBCXX_DEBUG
#include "race.h"
#include<bits/stdc++.h>
#define pb push_back
#define all(x) x.begin(), x.end()
using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
using pi = pair<int, int>;
int table[1000100];
vi used;
int get(int x) {
	if(x<0||x>1000100) return table[1000091];
	return table[x];
}
void mset(int x, int y) {
	if(x<0||x>1000100) return;
	table[x] = min(table[x], y);
	used.pb(x);
}
void clear() {
	for(auto i : used)
		table[i] = table[1000091];
	table[0] = 0;
	used.clear();
}
int n, k, ans = 10000001;
vector<vector<pi>> g;
vi sz, maxch, comp;
bitset<300300> is_centroid;
void sizes(int v, int p) {
	sz[v]=1, maxch[v]=0;
	comp.pb(v);
	for(auto ii : g[v]) {
		int i = ii.first;
		if(!is_centroid.test(i)&&i!=p)
			sizes(i, v), sz[v] += sz[i], maxch[v] = max(maxch[v], sz[i]);
	}
}
void dfsg(int v, int p, int d = 0, int vl = 0) {
	if(vl>k) return;
	ans = min(ans, d+get(k-vl));
	for(auto ii : g[v]) {
		int i = ii.first, c = ii.second;
		if(is_centroid.test(i)||i==p) continue;
		dfsg(i, v, d+1, vl+c);
	}
}
void dfss(int v, int p, int d = 0, int vl = 0) {
	if(vl>k) return;
	mset(vl, d);
	for(auto ii : g[v]) {
		int i = ii.first, c = ii.second;
		if(is_centroid.test(i)||i==p) continue;
		dfss(i, v, d+1, vl+c);
	}
}
void decompose(int v) {
	comp.clear();
	sizes(v, v);
	int c = comp[0];
	for(auto i : comp) {
		maxch[i] = max(maxch[i], (int)comp.size()-sz[i]);
		if(maxch[i]<maxch[c])c=i;
	}
	for(auto ii : g[c]) {
		int i = ii.first, cst = ii.second;
		if(is_centroid.test(i)) continue;
		dfsg(i, c, 1, cst);
		dfss(i, c, 1, cst);
	}
	clear();
	is_centroid.set(c);
	for(auto ii : g[c]) {
		int i = ii.first;
		if(!is_centroid.test(i))
			decompose(i);
	}
}

int best_path(int N, int K, int H[][2], int L[])
{
	memset(table, 0x3f, sizeof table), table[0] = 0;
	n=N,k=K;
	g.resize(n);
	sz.resize(n);
	maxch.resize(n);
	for(int i = 0; i+1 < n; i++) {
		g[H[i][0]].pb({H[i][1], L[i]});
		g[H[i][1]].pb({H[i][0], L[i]});
	}
	decompose(0);
	if(ans>n)ans=-1;
	return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 6 ms 4344 KB Output is correct
2 Correct 6 ms 4216 KB Output is correct
3 Correct 5 ms 4344 KB Output is correct
4 Correct 5 ms 4216 KB Output is correct
5 Correct 6 ms 4344 KB Output is correct
6 Correct 5 ms 4216 KB Output is correct
7 Correct 5 ms 4344 KB Output is correct
8 Correct 5 ms 4344 KB Output is correct
9 Correct 6 ms 4344 KB Output is correct
10 Correct 6 ms 4344 KB Output is correct
11 Correct 5 ms 4344 KB Output is correct
12 Correct 6 ms 4236 KB Output is correct
13 Correct 5 ms 4216 KB Output is correct
14 Correct 5 ms 4344 KB Output is correct
15 Correct 6 ms 4348 KB Output is correct
16 Correct 5 ms 4216 KB Output is correct
17 Correct 6 ms 4348 KB Output is correct
18 Correct 6 ms 4216 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 4344 KB Output is correct
2 Correct 6 ms 4216 KB Output is correct
3 Correct 5 ms 4344 KB Output is correct
4 Correct 5 ms 4216 KB Output is correct
5 Correct 6 ms 4344 KB Output is correct
6 Correct 5 ms 4216 KB Output is correct
7 Correct 5 ms 4344 KB Output is correct
8 Correct 5 ms 4344 KB Output is correct
9 Correct 6 ms 4344 KB Output is correct
10 Correct 6 ms 4344 KB Output is correct
11 Correct 5 ms 4344 KB Output is correct
12 Correct 6 ms 4236 KB Output is correct
13 Correct 5 ms 4216 KB Output is correct
14 Correct 5 ms 4344 KB Output is correct
15 Correct 6 ms 4348 KB Output is correct
16 Correct 5 ms 4216 KB Output is correct
17 Correct 6 ms 4348 KB Output is correct
18 Correct 6 ms 4216 KB Output is correct
19 Correct 5 ms 4216 KB Output is correct
20 Correct 5 ms 4216 KB Output is correct
21 Correct 8 ms 4344 KB Output is correct
22 Correct 8 ms 4472 KB Output is correct
23 Correct 8 ms 4348 KB Output is correct
24 Correct 7 ms 4344 KB Output is correct
25 Correct 8 ms 4344 KB Output is correct
26 Correct 8 ms 4344 KB Output is correct
27 Correct 7 ms 4344 KB Output is correct
28 Correct 8 ms 4344 KB Output is correct
29 Correct 9 ms 4344 KB Output is correct
30 Correct 8 ms 4344 KB Output is correct
31 Correct 9 ms 4344 KB Output is correct
32 Correct 9 ms 4344 KB Output is correct
33 Correct 9 ms 4344 KB Output is correct
34 Correct 8 ms 4344 KB Output is correct
35 Correct 8 ms 4472 KB Output is correct
36 Correct 9 ms 4472 KB Output is correct
37 Correct 9 ms 4344 KB Output is correct
38 Correct 9 ms 4344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 4344 KB Output is correct
2 Correct 6 ms 4216 KB Output is correct
3 Correct 5 ms 4344 KB Output is correct
4 Correct 5 ms 4216 KB Output is correct
5 Correct 6 ms 4344 KB Output is correct
6 Correct 5 ms 4216 KB Output is correct
7 Correct 5 ms 4344 KB Output is correct
8 Correct 5 ms 4344 KB Output is correct
9 Correct 6 ms 4344 KB Output is correct
10 Correct 6 ms 4344 KB Output is correct
11 Correct 5 ms 4344 KB Output is correct
12 Correct 6 ms 4236 KB Output is correct
13 Correct 5 ms 4216 KB Output is correct
14 Correct 5 ms 4344 KB Output is correct
15 Correct 6 ms 4348 KB Output is correct
16 Correct 5 ms 4216 KB Output is correct
17 Correct 6 ms 4348 KB Output is correct
18 Correct 6 ms 4216 KB Output is correct
19 Correct 557 ms 16616 KB Output is correct
20 Correct 524 ms 17400 KB Output is correct
21 Correct 605 ms 17648 KB Output is correct
22 Correct 580 ms 18084 KB Output is correct
23 Correct 471 ms 17772 KB Output is correct
24 Correct 299 ms 17528 KB Output is correct
25 Correct 771 ms 28340 KB Output is correct
26 Correct 750 ms 39284 KB Output is correct
27 Correct 638 ms 30836 KB Output is correct
28 Correct 1195 ms 73196 KB Output is correct
29 Correct 1185 ms 70040 KB Output is correct
30 Correct 627 ms 30836 KB Output is correct
31 Correct 659 ms 30716 KB Output is correct
32 Correct 700 ms 31152 KB Output is correct
33 Correct 1238 ms 30060 KB Output is correct
34 Correct 852 ms 30944 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 4344 KB Output is correct
2 Correct 6 ms 4216 KB Output is correct
3 Correct 5 ms 4344 KB Output is correct
4 Correct 5 ms 4216 KB Output is correct
5 Correct 6 ms 4344 KB Output is correct
6 Correct 5 ms 4216 KB Output is correct
7 Correct 5 ms 4344 KB Output is correct
8 Correct 5 ms 4344 KB Output is correct
9 Correct 6 ms 4344 KB Output is correct
10 Correct 6 ms 4344 KB Output is correct
11 Correct 5 ms 4344 KB Output is correct
12 Correct 6 ms 4236 KB Output is correct
13 Correct 5 ms 4216 KB Output is correct
14 Correct 5 ms 4344 KB Output is correct
15 Correct 6 ms 4348 KB Output is correct
16 Correct 5 ms 4216 KB Output is correct
17 Correct 6 ms 4348 KB Output is correct
18 Correct 6 ms 4216 KB Output is correct
19 Correct 5 ms 4216 KB Output is correct
20 Correct 5 ms 4216 KB Output is correct
21 Correct 8 ms 4344 KB Output is correct
22 Correct 8 ms 4472 KB Output is correct
23 Correct 8 ms 4348 KB Output is correct
24 Correct 7 ms 4344 KB Output is correct
25 Correct 8 ms 4344 KB Output is correct
26 Correct 8 ms 4344 KB Output is correct
27 Correct 7 ms 4344 KB Output is correct
28 Correct 8 ms 4344 KB Output is correct
29 Correct 9 ms 4344 KB Output is correct
30 Correct 8 ms 4344 KB Output is correct
31 Correct 9 ms 4344 KB Output is correct
32 Correct 9 ms 4344 KB Output is correct
33 Correct 9 ms 4344 KB Output is correct
34 Correct 8 ms 4344 KB Output is correct
35 Correct 8 ms 4472 KB Output is correct
36 Correct 9 ms 4472 KB Output is correct
37 Correct 9 ms 4344 KB Output is correct
38 Correct 9 ms 4344 KB Output is correct
39 Correct 557 ms 16616 KB Output is correct
40 Correct 524 ms 17400 KB Output is correct
41 Correct 605 ms 17648 KB Output is correct
42 Correct 580 ms 18084 KB Output is correct
43 Correct 471 ms 17772 KB Output is correct
44 Correct 299 ms 17528 KB Output is correct
45 Correct 771 ms 28340 KB Output is correct
46 Correct 750 ms 39284 KB Output is correct
47 Correct 638 ms 30836 KB Output is correct
48 Correct 1195 ms 73196 KB Output is correct
49 Correct 1185 ms 70040 KB Output is correct
50 Correct 627 ms 30836 KB Output is correct
51 Correct 659 ms 30716 KB Output is correct
52 Correct 700 ms 31152 KB Output is correct
53 Correct 1238 ms 30060 KB Output is correct
54 Correct 852 ms 30944 KB Output is correct
55 Correct 45 ms 5624 KB Output is correct
56 Correct 52 ms 5644 KB Output is correct
57 Correct 706 ms 18100 KB Output is correct
58 Correct 138 ms 18032 KB Output is correct
59 Correct 737 ms 39292 KB Output is correct
60 Correct 2458 ms 72428 KB Output is correct
61 Correct 731 ms 30964 KB Output is correct
62 Correct 818 ms 32056 KB Output is correct
63 Correct 933 ms 32112 KB Output is correct
64 Correct 1781 ms 32344 KB Output is correct
65 Correct 760 ms 31732 KB Output is correct
66 Correct 2050 ms 62800 KB Output is correct
67 Correct 423 ms 32980 KB Output is correct
68 Correct 941 ms 32020 KB Output is correct
69 Correct 1048 ms 32296 KB Output is correct
70 Correct 897 ms 30968 KB Output is correct