Submission #162552

# Submission time Handle Problem Language Result Execution time Memory
162552 2019-11-08T18:45:01 Z kostia244 Race (IOI11_race) C++14
21 / 100
3000 ms 17984 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(d>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(d>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 8 ms 4344 KB Output is correct
2 Correct 8 ms 4216 KB Output is correct
3 Correct 8 ms 4344 KB Output is correct
4 Correct 8 ms 4344 KB Output is correct
5 Correct 7 ms 4344 KB Output is correct
6 Correct 8 ms 4344 KB Output is correct
7 Correct 8 ms 4344 KB Output is correct
8 Correct 8 ms 4216 KB Output is correct
9 Correct 8 ms 4344 KB Output is correct
10 Correct 8 ms 4216 KB Output is correct
11 Correct 7 ms 4344 KB Output is correct
12 Correct 8 ms 4216 KB Output is correct
13 Correct 8 ms 4344 KB Output is correct
14 Correct 7 ms 4344 KB Output is correct
15 Correct 8 ms 4344 KB Output is correct
16 Correct 8 ms 4216 KB Output is correct
17 Correct 7 ms 4216 KB Output is correct
18 Correct 7 ms 4216 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 4344 KB Output is correct
2 Correct 8 ms 4216 KB Output is correct
3 Correct 8 ms 4344 KB Output is correct
4 Correct 8 ms 4344 KB Output is correct
5 Correct 7 ms 4344 KB Output is correct
6 Correct 8 ms 4344 KB Output is correct
7 Correct 8 ms 4344 KB Output is correct
8 Correct 8 ms 4216 KB Output is correct
9 Correct 8 ms 4344 KB Output is correct
10 Correct 8 ms 4216 KB Output is correct
11 Correct 7 ms 4344 KB Output is correct
12 Correct 8 ms 4216 KB Output is correct
13 Correct 8 ms 4344 KB Output is correct
14 Correct 7 ms 4344 KB Output is correct
15 Correct 8 ms 4344 KB Output is correct
16 Correct 8 ms 4216 KB Output is correct
17 Correct 7 ms 4216 KB Output is correct
18 Correct 7 ms 4216 KB Output is correct
19 Correct 5 ms 4216 KB Output is correct
20 Correct 7 ms 4216 KB Output is correct
21 Correct 221 ms 4688 KB Output is correct
22 Correct 212 ms 4576 KB Output is correct
23 Correct 211 ms 4600 KB Output is correct
24 Correct 207 ms 4600 KB Output is correct
25 Correct 274 ms 4644 KB Output is correct
26 Correct 210 ms 4600 KB Output is correct
27 Correct 205 ms 4600 KB Output is correct
28 Correct 268 ms 4616 KB Output is correct
29 Correct 246 ms 4600 KB Output is correct
30 Correct 273 ms 4600 KB Output is correct
31 Correct 267 ms 4600 KB Output is correct
32 Correct 275 ms 4600 KB Output is correct
33 Correct 312 ms 4600 KB Output is correct
34 Correct 184 ms 4600 KB Output is correct
35 Correct 173 ms 4656 KB Output is correct
36 Correct 150 ms 4728 KB Output is correct
37 Correct 192 ms 4524 KB Output is correct
38 Correct 213 ms 4572 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 4344 KB Output is correct
2 Correct 8 ms 4216 KB Output is correct
3 Correct 8 ms 4344 KB Output is correct
4 Correct 8 ms 4344 KB Output is correct
5 Correct 7 ms 4344 KB Output is correct
6 Correct 8 ms 4344 KB Output is correct
7 Correct 8 ms 4344 KB Output is correct
8 Correct 8 ms 4216 KB Output is correct
9 Correct 8 ms 4344 KB Output is correct
10 Correct 8 ms 4216 KB Output is correct
11 Correct 7 ms 4344 KB Output is correct
12 Correct 8 ms 4216 KB Output is correct
13 Correct 8 ms 4344 KB Output is correct
14 Correct 7 ms 4344 KB Output is correct
15 Correct 8 ms 4344 KB Output is correct
16 Correct 8 ms 4216 KB Output is correct
17 Correct 7 ms 4216 KB Output is correct
18 Correct 7 ms 4216 KB Output is correct
19 Execution timed out 3037 ms 17984 KB Time limit exceeded
20 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 8 ms 4344 KB Output is correct
2 Correct 8 ms 4216 KB Output is correct
3 Correct 8 ms 4344 KB Output is correct
4 Correct 8 ms 4344 KB Output is correct
5 Correct 7 ms 4344 KB Output is correct
6 Correct 8 ms 4344 KB Output is correct
7 Correct 8 ms 4344 KB Output is correct
8 Correct 8 ms 4216 KB Output is correct
9 Correct 8 ms 4344 KB Output is correct
10 Correct 8 ms 4216 KB Output is correct
11 Correct 7 ms 4344 KB Output is correct
12 Correct 8 ms 4216 KB Output is correct
13 Correct 8 ms 4344 KB Output is correct
14 Correct 7 ms 4344 KB Output is correct
15 Correct 8 ms 4344 KB Output is correct
16 Correct 8 ms 4216 KB Output is correct
17 Correct 7 ms 4216 KB Output is correct
18 Correct 7 ms 4216 KB Output is correct
19 Correct 5 ms 4216 KB Output is correct
20 Correct 7 ms 4216 KB Output is correct
21 Correct 221 ms 4688 KB Output is correct
22 Correct 212 ms 4576 KB Output is correct
23 Correct 211 ms 4600 KB Output is correct
24 Correct 207 ms 4600 KB Output is correct
25 Correct 274 ms 4644 KB Output is correct
26 Correct 210 ms 4600 KB Output is correct
27 Correct 205 ms 4600 KB Output is correct
28 Correct 268 ms 4616 KB Output is correct
29 Correct 246 ms 4600 KB Output is correct
30 Correct 273 ms 4600 KB Output is correct
31 Correct 267 ms 4600 KB Output is correct
32 Correct 275 ms 4600 KB Output is correct
33 Correct 312 ms 4600 KB Output is correct
34 Correct 184 ms 4600 KB Output is correct
35 Correct 173 ms 4656 KB Output is correct
36 Correct 150 ms 4728 KB Output is correct
37 Correct 192 ms 4524 KB Output is correct
38 Correct 213 ms 4572 KB Output is correct
39 Execution timed out 3037 ms 17984 KB Time limit exceeded
40 Halted 0 ms 0 KB -