Submission #96995

# Submission time Handle Problem Language Result Execution time Memory
96995 2019-02-13T08:14:50 Z tugushka Race (IOI11_race) C++14
100 / 100
2360 ms 44348 KB
#include "race.h"
#include <bits/stdc++.h>
#define N 200005
using namespace std;

using pii = pair < int, int >;

map < int, int > x, y;
vector < list < pair < int, int > > > to;
int n, k, sz[N], res = 1e9;
bool blocked[N];

int get_size(int u, int p){
	sz[u] = 1;
	for( pii v : to[u] ){
		if( blocked[v.first] || v.first == p ) continue;
		sz[u] += get_size( v.first, u );
	}
	return sz[u];
}

int get_center( int u, int p, int comp_size ){
	for( pii v : to[u] ){
		if( blocked[v.first] || v.first == p ) continue;
		if( sz[v.first] > comp_size ) return get_center(v.first, u, comp_size);
	}
	return u;
}

void dfs(int u, int p, int len, int dis){
	if( y.find( len ) == y.end() ) y[len] = dis;
	else{
		y[len] = min( dis, y[len] );
	}

	for( pii v : to[u] ){
		if( blocked[v.first] || v.first == p ) continue;
		dfs( v.first, u, len + v.second, dis + 1 );
	}
}

void decomp(int u){
	u = get_center(u, -1, get_size(u, -1)/2);

	x.clear();
	x[0] = 0;
	for( pii v : to[u] ){
		if( blocked[v.first] ) continue;
		y.clear();
		dfs( v.first, u, v.second, 1 );
		for( pii now : y ){
			if( x.find( k-now.first ) != x.end() ){
				res = min( res, x[k-now.first] + now.second );
			}
		}

		for( pii now : y ){
			if( x.find( now.first ) == x.end() ) x[now.first] = now.second;
			else{
				x[now.first] = min( x[now.first], now.second );
			}
		}
	}

	blocked[u] = 1;
	for( pii v : to[u] ){
		if( blocked[v.first] ) continue;
		decomp( v.first );
	}

}

int best_path(int NN, int K, int H[][2], int L[]){
	n = NN, k = K;
	to.resize(n);
	for(int i = 0 ; i < n-1 ; i++){
		to[ H[i][0] ].push_back( make_pair( H[i][1], L[i] ) );
		to[ H[i][1] ].push_back( make_pair( H[i][0], L[i] ) );
	}

	decomp( 0 );

	return res == 1e9 ? -1 : res;
}

# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 3 ms 384 KB Output is correct
3 Correct 3 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 3 ms 512 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 3 ms 512 KB Output is correct
8 Correct 3 ms 512 KB Output is correct
9 Correct 3 ms 512 KB Output is correct
10 Correct 3 ms 384 KB Output is correct
11 Correct 2 ms 384 KB Output is correct
12 Correct 3 ms 384 KB Output is correct
13 Correct 2 ms 384 KB Output is correct
14 Correct 3 ms 384 KB Output is correct
15 Correct 3 ms 384 KB Output is correct
16 Correct 3 ms 384 KB Output is correct
17 Correct 2 ms 384 KB Output is correct
18 Correct 2 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 3 ms 384 KB Output is correct
3 Correct 3 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 3 ms 512 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 3 ms 512 KB Output is correct
8 Correct 3 ms 512 KB Output is correct
9 Correct 3 ms 512 KB Output is correct
10 Correct 3 ms 384 KB Output is correct
11 Correct 2 ms 384 KB Output is correct
12 Correct 3 ms 384 KB Output is correct
13 Correct 2 ms 384 KB Output is correct
14 Correct 3 ms 384 KB Output is correct
15 Correct 3 ms 384 KB Output is correct
16 Correct 3 ms 384 KB Output is correct
17 Correct 2 ms 384 KB Output is correct
18 Correct 2 ms 384 KB Output is correct
19 Correct 3 ms 384 KB Output is correct
20 Correct 3 ms 384 KB Output is correct
21 Correct 4 ms 512 KB Output is correct
22 Correct 5 ms 512 KB Output is correct
23 Correct 5 ms 512 KB Output is correct
24 Correct 5 ms 512 KB Output is correct
25 Correct 5 ms 512 KB Output is correct
26 Correct 4 ms 512 KB Output is correct
27 Correct 3 ms 384 KB Output is correct
28 Correct 6 ms 512 KB Output is correct
29 Correct 4 ms 512 KB Output is correct
30 Correct 5 ms 512 KB Output is correct
31 Correct 5 ms 488 KB Output is correct
32 Correct 5 ms 512 KB Output is correct
33 Correct 6 ms 512 KB Output is correct
34 Correct 5 ms 512 KB Output is correct
35 Correct 5 ms 512 KB Output is correct
36 Correct 5 ms 640 KB Output is correct
37 Correct 4 ms 512 KB Output is correct
38 Correct 4 ms 512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 3 ms 384 KB Output is correct
3 Correct 3 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 3 ms 512 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 3 ms 512 KB Output is correct
8 Correct 3 ms 512 KB Output is correct
9 Correct 3 ms 512 KB Output is correct
10 Correct 3 ms 384 KB Output is correct
11 Correct 2 ms 384 KB Output is correct
12 Correct 3 ms 384 KB Output is correct
13 Correct 2 ms 384 KB Output is correct
14 Correct 3 ms 384 KB Output is correct
15 Correct 3 ms 384 KB Output is correct
16 Correct 3 ms 384 KB Output is correct
17 Correct 2 ms 384 KB Output is correct
18 Correct 2 ms 384 KB Output is correct
19 Correct 381 ms 10688 KB Output is correct
20 Correct 428 ms 10644 KB Output is correct
21 Correct 391 ms 10720 KB Output is correct
22 Correct 313 ms 10616 KB Output is correct
23 Correct 590 ms 10732 KB Output is correct
24 Correct 220 ms 10616 KB Output is correct
25 Correct 311 ms 15068 KB Output is correct
26 Correct 133 ms 15528 KB Output is correct
27 Correct 575 ms 20984 KB Output is correct
28 Correct 2130 ms 44348 KB Output is correct
29 Correct 2020 ms 43768 KB Output is correct
30 Correct 520 ms 21084 KB Output is correct
31 Correct 558 ms 20984 KB Output is correct
32 Correct 686 ms 21028 KB Output is correct
33 Correct 989 ms 21368 KB Output is correct
34 Correct 1880 ms 32768 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 3 ms 384 KB Output is correct
3 Correct 3 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 3 ms 512 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 3 ms 512 KB Output is correct
8 Correct 3 ms 512 KB Output is correct
9 Correct 3 ms 512 KB Output is correct
10 Correct 3 ms 384 KB Output is correct
11 Correct 2 ms 384 KB Output is correct
12 Correct 3 ms 384 KB Output is correct
13 Correct 2 ms 384 KB Output is correct
14 Correct 3 ms 384 KB Output is correct
15 Correct 3 ms 384 KB Output is correct
16 Correct 3 ms 384 KB Output is correct
17 Correct 2 ms 384 KB Output is correct
18 Correct 2 ms 384 KB Output is correct
19 Correct 3 ms 384 KB Output is correct
20 Correct 3 ms 384 KB Output is correct
21 Correct 4 ms 512 KB Output is correct
22 Correct 5 ms 512 KB Output is correct
23 Correct 5 ms 512 KB Output is correct
24 Correct 5 ms 512 KB Output is correct
25 Correct 5 ms 512 KB Output is correct
26 Correct 4 ms 512 KB Output is correct
27 Correct 3 ms 384 KB Output is correct
28 Correct 6 ms 512 KB Output is correct
29 Correct 4 ms 512 KB Output is correct
30 Correct 5 ms 512 KB Output is correct
31 Correct 5 ms 488 KB Output is correct
32 Correct 5 ms 512 KB Output is correct
33 Correct 6 ms 512 KB Output is correct
34 Correct 5 ms 512 KB Output is correct
35 Correct 5 ms 512 KB Output is correct
36 Correct 5 ms 640 KB Output is correct
37 Correct 4 ms 512 KB Output is correct
38 Correct 4 ms 512 KB Output is correct
39 Correct 381 ms 10688 KB Output is correct
40 Correct 428 ms 10644 KB Output is correct
41 Correct 391 ms 10720 KB Output is correct
42 Correct 313 ms 10616 KB Output is correct
43 Correct 590 ms 10732 KB Output is correct
44 Correct 220 ms 10616 KB Output is correct
45 Correct 311 ms 15068 KB Output is correct
46 Correct 133 ms 15528 KB Output is correct
47 Correct 575 ms 20984 KB Output is correct
48 Correct 2130 ms 44348 KB Output is correct
49 Correct 2020 ms 43768 KB Output is correct
50 Correct 520 ms 21084 KB Output is correct
51 Correct 558 ms 20984 KB Output is correct
52 Correct 686 ms 21028 KB Output is correct
53 Correct 989 ms 21368 KB Output is correct
54 Correct 1880 ms 32768 KB Output is correct
55 Correct 38 ms 1764 KB Output is correct
56 Correct 26 ms 1408 KB Output is correct
57 Correct 194 ms 10744 KB Output is correct
58 Correct 70 ms 10616 KB Output is correct
59 Correct 602 ms 21468 KB Output is correct
60 Correct 2242 ms 43128 KB Output is correct
61 Correct 662 ms 22316 KB Output is correct
62 Correct 528 ms 21164 KB Output is correct
63 Correct 634 ms 20984 KB Output is correct
64 Correct 2073 ms 27640 KB Output is correct
65 Correct 1917 ms 30844 KB Output is correct
66 Correct 2360 ms 42872 KB Output is correct
67 Correct 301 ms 20984 KB Output is correct
68 Correct 1181 ms 28536 KB Output is correct
69 Correct 1071 ms 28924 KB Output is correct
70 Correct 981 ms 27324 KB Output is correct