답안 #96998

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
96998 2019-02-13T08:23:16 Z tugushka 경주 (Race) (IOI11_race) C++14
100 / 100
2077 ms 36620 KB
#include "race.h"
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define N 200005
using namespace std;

using pii = pair < int, int >;

map < int, int > x, y;
vector < vector < 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;
}

# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 384 KB Output is correct
2 Correct 2 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 384 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 3 ms 384 KB Output is correct
8 Correct 3 ms 384 KB Output is correct
9 Correct 3 ms 384 KB Output is correct
10 Correct 2 ms 384 KB Output is correct
11 Correct 3 ms 384 KB Output is correct
12 Correct 2 ms 384 KB Output is correct
13 Correct 2 ms 384 KB Output is correct
14 Correct 2 ms 384 KB Output is correct
15 Correct 2 ms 384 KB Output is correct
16 Correct 3 ms 304 KB Output is correct
17 Correct 2 ms 384 KB Output is correct
18 Correct 2 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 384 KB Output is correct
2 Correct 2 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 384 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 3 ms 384 KB Output is correct
8 Correct 3 ms 384 KB Output is correct
9 Correct 3 ms 384 KB Output is correct
10 Correct 2 ms 384 KB Output is correct
11 Correct 3 ms 384 KB Output is correct
12 Correct 2 ms 384 KB Output is correct
13 Correct 2 ms 384 KB Output is correct
14 Correct 2 ms 384 KB Output is correct
15 Correct 2 ms 384 KB Output is correct
16 Correct 3 ms 304 KB Output is correct
17 Correct 2 ms 384 KB Output is correct
18 Correct 2 ms 384 KB Output is correct
19 Correct 2 ms 384 KB Output is correct
20 Correct 2 ms 384 KB Output is correct
21 Correct 5 ms 512 KB Output is correct
22 Correct 4 ms 512 KB Output is correct
23 Correct 6 ms 512 KB Output is correct
24 Correct 5 ms 512 KB Output is correct
25 Correct 4 ms 512 KB Output is correct
26 Correct 5 ms 512 KB Output is correct
27 Correct 3 ms 384 KB Output is correct
28 Correct 4 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 512 KB Output is correct
32 Correct 4 ms 512 KB Output is correct
33 Correct 5 ms 512 KB Output is correct
34 Correct 5 ms 512 KB Output is correct
35 Correct 5 ms 540 KB Output is correct
36 Correct 4 ms 512 KB Output is correct
37 Correct 4 ms 512 KB Output is correct
38 Correct 5 ms 512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 384 KB Output is correct
2 Correct 2 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 384 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 3 ms 384 KB Output is correct
8 Correct 3 ms 384 KB Output is correct
9 Correct 3 ms 384 KB Output is correct
10 Correct 2 ms 384 KB Output is correct
11 Correct 3 ms 384 KB Output is correct
12 Correct 2 ms 384 KB Output is correct
13 Correct 2 ms 384 KB Output is correct
14 Correct 2 ms 384 KB Output is correct
15 Correct 2 ms 384 KB Output is correct
16 Correct 3 ms 304 KB Output is correct
17 Correct 2 ms 384 KB Output is correct
18 Correct 2 ms 384 KB Output is correct
19 Correct 375 ms 8024 KB Output is correct
20 Correct 407 ms 8056 KB Output is correct
21 Correct 340 ms 8056 KB Output is correct
22 Correct 314 ms 8104 KB Output is correct
23 Correct 496 ms 8440 KB Output is correct
24 Correct 194 ms 8184 KB Output is correct
25 Correct 322 ms 11896 KB Output is correct
26 Correct 106 ms 11532 KB Output is correct
27 Correct 471 ms 16248 KB Output is correct
28 Correct 1893 ms 36600 KB Output is correct
29 Correct 1894 ms 36520 KB Output is correct
30 Correct 464 ms 16252 KB Output is correct
31 Correct 498 ms 16172 KB Output is correct
32 Correct 536 ms 16136 KB Output is correct
33 Correct 956 ms 14968 KB Output is correct
34 Correct 1671 ms 26488 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 384 KB Output is correct
2 Correct 2 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 384 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 3 ms 384 KB Output is correct
8 Correct 3 ms 384 KB Output is correct
9 Correct 3 ms 384 KB Output is correct
10 Correct 2 ms 384 KB Output is correct
11 Correct 3 ms 384 KB Output is correct
12 Correct 2 ms 384 KB Output is correct
13 Correct 2 ms 384 KB Output is correct
14 Correct 2 ms 384 KB Output is correct
15 Correct 2 ms 384 KB Output is correct
16 Correct 3 ms 304 KB Output is correct
17 Correct 2 ms 384 KB Output is correct
18 Correct 2 ms 384 KB Output is correct
19 Correct 2 ms 384 KB Output is correct
20 Correct 2 ms 384 KB Output is correct
21 Correct 5 ms 512 KB Output is correct
22 Correct 4 ms 512 KB Output is correct
23 Correct 6 ms 512 KB Output is correct
24 Correct 5 ms 512 KB Output is correct
25 Correct 4 ms 512 KB Output is correct
26 Correct 5 ms 512 KB Output is correct
27 Correct 3 ms 384 KB Output is correct
28 Correct 4 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 512 KB Output is correct
32 Correct 4 ms 512 KB Output is correct
33 Correct 5 ms 512 KB Output is correct
34 Correct 5 ms 512 KB Output is correct
35 Correct 5 ms 540 KB Output is correct
36 Correct 4 ms 512 KB Output is correct
37 Correct 4 ms 512 KB Output is correct
38 Correct 5 ms 512 KB Output is correct
39 Correct 375 ms 8024 KB Output is correct
40 Correct 407 ms 8056 KB Output is correct
41 Correct 340 ms 8056 KB Output is correct
42 Correct 314 ms 8104 KB Output is correct
43 Correct 496 ms 8440 KB Output is correct
44 Correct 194 ms 8184 KB Output is correct
45 Correct 322 ms 11896 KB Output is correct
46 Correct 106 ms 11532 KB Output is correct
47 Correct 471 ms 16248 KB Output is correct
48 Correct 1893 ms 36600 KB Output is correct
49 Correct 1894 ms 36520 KB Output is correct
50 Correct 464 ms 16252 KB Output is correct
51 Correct 498 ms 16172 KB Output is correct
52 Correct 536 ms 16136 KB Output is correct
53 Correct 956 ms 14968 KB Output is correct
54 Correct 1671 ms 26488 KB Output is correct
55 Correct 35 ms 1536 KB Output is correct
56 Correct 23 ms 1180 KB Output is correct
57 Correct 179 ms 8412 KB Output is correct
58 Correct 60 ms 8300 KB Output is correct
59 Correct 526 ms 17400 KB Output is correct
60 Correct 2077 ms 35864 KB Output is correct
61 Correct 605 ms 17576 KB Output is correct
62 Correct 525 ms 16136 KB Output is correct
63 Correct 572 ms 16092 KB Output is correct
64 Correct 1590 ms 22392 KB Output is correct
65 Correct 1469 ms 25592 KB Output is correct
66 Correct 1658 ms 36620 KB Output is correct
67 Correct 242 ms 16232 KB Output is correct
68 Correct 818 ms 24100 KB Output is correct
69 Correct 850 ms 24412 KB Output is correct
70 Correct 819 ms 22940 KB Output is correct