Submission #77379

# Submission time Handle Problem Language Result Execution time Memory
77379 2018-09-27T02:49:42 Z joseacaz Race (IOI11_race) C++17
100 / 100
720 ms 65868 KB
#include "race.h"
#include <vector>
#define MAXN 200005
#define MAXK 1000005
#define pii pair < int, int >
#define mp make_pair

using namespace std;

int C, K, tam[MAXN], dead[MAXN], tim[MAXK], arr[MAXK];
vector < pii > Graph[MAXN];

void pre_tam ( int node, int parent )
{
	tam[node] = 1;
	for ( auto i : Graph[node] )
		if ( i.first != parent && !dead[i.first] )
			pre_tam ( i.first, node ), tam[node] += tam[i.first];
}

int find_centroid ( int node, int parent, int siz )
{
	for ( auto i : Graph[node] )
		if ( i.first != parent && 2 * tam[i.first] > siz && !dead[i.first] )
			return find_centroid ( i.first, node, siz );
	return node;
}

int qry ( int node, int parent, int s, int a )
{
	if ( s > K )
		return (1 << 30);

	int ret = (1<<30);
	if ( tim[K - s] == C )
		ret = arr[K - s] + a;

	for ( auto i : Graph[node] )
		if ( !dead[i.first] && i.first != parent )
			ret = min ( qry ( i.first, node, s + i.second, a + 1 ), ret );

	return ret;
}

void upd ( int node, int parent, int s, int a )
{
	if ( s > K )
		return;

	if ( tim[s] != C )
	{
		arr[s] = a;
		tim[s] = C;
	}
	else
		arr[s] = min ( arr[s], a );

	for ( auto i : Graph[node] )
		if ( !dead[i.first] && i.first != parent )
			upd ( i.first, node, s + i.second, a + 1 );
}

int solve ( int node )
{
	pre_tam ( node, -1 );
	node = find_centroid ( node, -1, tam[node] );

	C++;
	tim[0] = C;
	arr[0] = 0;

	int ans = (1<<30);
	for ( auto i : Graph[node] )
	{
		if ( !dead[i.first] )
		{
			ans = min ( qry ( i.first, node, i.second, 1 ), ans );
			upd ( i.first, node, i.second, 1 );
		}
	}

	dead[node] = 1;
	for ( auto i : Graph[node] )
		if ( !dead[i.first] )
			ans = min ( ans, solve ( i.first ) );
	
	return ans;
}

int best_path ( int N, int _k, int H[][2], int L[] )
{
	K = _k;
	int u, v;
	for ( int i = 0; i < N - 1; i++ )
	{
		u = H[i][0];
		v = H[i][1];

		Graph[u].push_back ( mp ( v, L[i] ) );
		Graph[v].push_back ( mp ( u, L[i] ) );
	}

	int retval = solve ( 0 );
	if ( retval == (1 << 30) )
		return -1;
	return retval;
}
# Verdict Execution time Memory Grader output
1 Correct 6 ms 4984 KB Output is correct
2 Correct 6 ms 5220 KB Output is correct
3 Correct 6 ms 5252 KB Output is correct
4 Correct 6 ms 5252 KB Output is correct
5 Correct 6 ms 5252 KB Output is correct
6 Correct 6 ms 5252 KB Output is correct
7 Correct 6 ms 5252 KB Output is correct
8 Correct 6 ms 5376 KB Output is correct
9 Correct 6 ms 5376 KB Output is correct
10 Correct 6 ms 5376 KB Output is correct
11 Correct 6 ms 5376 KB Output is correct
12 Correct 6 ms 5500 KB Output is correct
13 Correct 6 ms 5500 KB Output is correct
14 Correct 6 ms 5500 KB Output is correct
15 Correct 5 ms 5500 KB Output is correct
16 Correct 6 ms 5500 KB Output is correct
17 Correct 6 ms 5500 KB Output is correct
18 Correct 6 ms 5500 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 4984 KB Output is correct
2 Correct 6 ms 5220 KB Output is correct
3 Correct 6 ms 5252 KB Output is correct
4 Correct 6 ms 5252 KB Output is correct
5 Correct 6 ms 5252 KB Output is correct
6 Correct 6 ms 5252 KB Output is correct
7 Correct 6 ms 5252 KB Output is correct
8 Correct 6 ms 5376 KB Output is correct
9 Correct 6 ms 5376 KB Output is correct
10 Correct 6 ms 5376 KB Output is correct
11 Correct 6 ms 5376 KB Output is correct
12 Correct 6 ms 5500 KB Output is correct
13 Correct 6 ms 5500 KB Output is correct
14 Correct 6 ms 5500 KB Output is correct
15 Correct 5 ms 5500 KB Output is correct
16 Correct 6 ms 5500 KB Output is correct
17 Correct 6 ms 5500 KB Output is correct
18 Correct 6 ms 5500 KB Output is correct
19 Correct 6 ms 5500 KB Output is correct
20 Correct 6 ms 5500 KB Output is correct
21 Correct 6 ms 5500 KB Output is correct
22 Correct 11 ms 10452 KB Output is correct
23 Correct 11 ms 10452 KB Output is correct
24 Correct 13 ms 11124 KB Output is correct
25 Correct 10 ms 11124 KB Output is correct
26 Correct 10 ms 11124 KB Output is correct
27 Correct 7 ms 11124 KB Output is correct
28 Correct 8 ms 11124 KB Output is correct
29 Correct 9 ms 11124 KB Output is correct
30 Correct 10 ms 11124 KB Output is correct
31 Correct 10 ms 11124 KB Output is correct
32 Correct 11 ms 11124 KB Output is correct
33 Correct 12 ms 11124 KB Output is correct
34 Correct 11 ms 11124 KB Output is correct
35 Correct 12 ms 11428 KB Output is correct
36 Correct 14 ms 12080 KB Output is correct
37 Correct 10 ms 12080 KB Output is correct
38 Correct 9 ms 12080 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 4984 KB Output is correct
2 Correct 6 ms 5220 KB Output is correct
3 Correct 6 ms 5252 KB Output is correct
4 Correct 6 ms 5252 KB Output is correct
5 Correct 6 ms 5252 KB Output is correct
6 Correct 6 ms 5252 KB Output is correct
7 Correct 6 ms 5252 KB Output is correct
8 Correct 6 ms 5376 KB Output is correct
9 Correct 6 ms 5376 KB Output is correct
10 Correct 6 ms 5376 KB Output is correct
11 Correct 6 ms 5376 KB Output is correct
12 Correct 6 ms 5500 KB Output is correct
13 Correct 6 ms 5500 KB Output is correct
14 Correct 6 ms 5500 KB Output is correct
15 Correct 5 ms 5500 KB Output is correct
16 Correct 6 ms 5500 KB Output is correct
17 Correct 6 ms 5500 KB Output is correct
18 Correct 6 ms 5500 KB Output is correct
19 Correct 173 ms 12652 KB Output is correct
20 Correct 150 ms 13980 KB Output is correct
21 Correct 160 ms 15372 KB Output is correct
22 Correct 149 ms 16812 KB Output is correct
23 Correct 94 ms 18324 KB Output is correct
24 Correct 72 ms 19752 KB Output is correct
25 Correct 164 ms 23724 KB Output is correct
26 Correct 111 ms 28020 KB Output is correct
27 Correct 199 ms 30924 KB Output is correct
28 Correct 346 ms 45216 KB Output is correct
29 Correct 367 ms 47408 KB Output is correct
30 Correct 197 ms 47408 KB Output is correct
31 Correct 193 ms 47408 KB Output is correct
32 Correct 251 ms 47408 KB Output is correct
33 Correct 307 ms 47408 KB Output is correct
34 Correct 361 ms 47408 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 4984 KB Output is correct
2 Correct 6 ms 5220 KB Output is correct
3 Correct 6 ms 5252 KB Output is correct
4 Correct 6 ms 5252 KB Output is correct
5 Correct 6 ms 5252 KB Output is correct
6 Correct 6 ms 5252 KB Output is correct
7 Correct 6 ms 5252 KB Output is correct
8 Correct 6 ms 5376 KB Output is correct
9 Correct 6 ms 5376 KB Output is correct
10 Correct 6 ms 5376 KB Output is correct
11 Correct 6 ms 5376 KB Output is correct
12 Correct 6 ms 5500 KB Output is correct
13 Correct 6 ms 5500 KB Output is correct
14 Correct 6 ms 5500 KB Output is correct
15 Correct 5 ms 5500 KB Output is correct
16 Correct 6 ms 5500 KB Output is correct
17 Correct 6 ms 5500 KB Output is correct
18 Correct 6 ms 5500 KB Output is correct
19 Correct 6 ms 5500 KB Output is correct
20 Correct 6 ms 5500 KB Output is correct
21 Correct 6 ms 5500 KB Output is correct
22 Correct 11 ms 10452 KB Output is correct
23 Correct 11 ms 10452 KB Output is correct
24 Correct 13 ms 11124 KB Output is correct
25 Correct 10 ms 11124 KB Output is correct
26 Correct 10 ms 11124 KB Output is correct
27 Correct 7 ms 11124 KB Output is correct
28 Correct 8 ms 11124 KB Output is correct
29 Correct 9 ms 11124 KB Output is correct
30 Correct 10 ms 11124 KB Output is correct
31 Correct 10 ms 11124 KB Output is correct
32 Correct 11 ms 11124 KB Output is correct
33 Correct 12 ms 11124 KB Output is correct
34 Correct 11 ms 11124 KB Output is correct
35 Correct 12 ms 11428 KB Output is correct
36 Correct 14 ms 12080 KB Output is correct
37 Correct 10 ms 12080 KB Output is correct
38 Correct 9 ms 12080 KB Output is correct
39 Correct 173 ms 12652 KB Output is correct
40 Correct 150 ms 13980 KB Output is correct
41 Correct 160 ms 15372 KB Output is correct
42 Correct 149 ms 16812 KB Output is correct
43 Correct 94 ms 18324 KB Output is correct
44 Correct 72 ms 19752 KB Output is correct
45 Correct 164 ms 23724 KB Output is correct
46 Correct 111 ms 28020 KB Output is correct
47 Correct 199 ms 30924 KB Output is correct
48 Correct 346 ms 45216 KB Output is correct
49 Correct 367 ms 47408 KB Output is correct
50 Correct 197 ms 47408 KB Output is correct
51 Correct 193 ms 47408 KB Output is correct
52 Correct 251 ms 47408 KB Output is correct
53 Correct 307 ms 47408 KB Output is correct
54 Correct 361 ms 47408 KB Output is correct
55 Correct 16 ms 47408 KB Output is correct
56 Correct 17 ms 47408 KB Output is correct
57 Correct 90 ms 47408 KB Output is correct
58 Correct 46 ms 47408 KB Output is correct
59 Correct 121 ms 47408 KB Output is correct
60 Correct 649 ms 59016 KB Output is correct
61 Correct 231 ms 59016 KB Output is correct
62 Correct 271 ms 59016 KB Output is correct
63 Correct 339 ms 59016 KB Output is correct
64 Correct 720 ms 59016 KB Output is correct
65 Correct 244 ms 59016 KB Output is correct
66 Correct 603 ms 65868 KB Output is correct
67 Correct 130 ms 65868 KB Output is correct
68 Correct 312 ms 65868 KB Output is correct
69 Correct 334 ms 65868 KB Output is correct
70 Correct 290 ms 65868 KB Output is correct