Submission #121580

# Submission time Handle Problem Language Result Execution time Memory
121580 2019-06-26T19:38:49 Z DodgeBallMan Race (IOI11_race) C++14
21 / 100
300 ms 26068 KB
#include <bits/stdc++.h>
#define pii pair<int ,int> 
#define x first
#define y second
using namespace std;

const int N = 2e5+100;
int n, dep[N], ver[N], st[N], ft[N], hv[N], ti, ans = 1e9;
map<long long, int> m;
vector<pii> g[N];
long long path[N], k;

int pre( int u, int p ) {
	st[u] = ++ti;
	ver[ti] = u, dep[u] = dep[p] + 1;
	int sz = 1; pii ret( 0, -1 );
	for( pii i : g[u] ) if( i.x != p ) {
		path[i.x] = path[u] + i.y;
		int z = pre( i.x, u );
		sz += z;
		ret = max( ret, pii( z, i.x ) );
	}
	hv[u] = ret.y;
	ft[u] = ti;
	return sz;
}

void sack( int now, int p, bool keep ) {
	for( pii i : g[now] ) if( i.x != p && i.x != hv[now] ) sack( i.x, now, 0 );
	if( hv[now] != -1 ) sack( hv[now], now, 1 );
	if( m[path[now]] == 0 ) m[path[now]] = dep[now];
	else m[path[now]] = min( dep[now], m[path[now]] );
	if( m[path[now]+k] != 0 ) ans = min( ans, m[path[now]+k] - dep[now] );
	// cout << "im here " << now << endl;
	// for( auto it = m.begin() ; it != m.end() ; it++ ) cout << it->first << " " << it->second << endl;
	for( pii u : g[now] ) if( u.x != p && u.x != hv[now] ) {
		for( int i = st[u.x] ; i <= ft[u.x] ; i++ ) if( m[2LL*path[now]+k-path[ver[i]]] != 0 ) {
			ans = min( ans, dep[ver[i]] + m[2LL*path[now]+k-path[ver[i]]] - 2*dep[now] );
		}
		for( int i = st[u.x] ; i <= ft[u.x] ; i++ ) {
			if( m[path[ver[i]]] == 0 ) m[path[ver[i]]] = dep[ver[i]];
			else m[path[ver[i]]] = min( dep[ver[i]], m[path[ver[i]]] );
		}
	}
	if( !keep ) m.clear();
}

int best_path( int N, int K, int H[][2], int L[] ) {
	n = N, k = K;
	for( int i = 0 ; i < n - 1 ; i++ ) {
		g[H[i][0]].emplace_back( H[i][1], L[i] );
		g[H[i][1]].emplace_back( H[i][0], L[i] );
	}
	pre( 1, 0 ), sack( 1, 0, 1 );
	return ( ans != 1e9 ) ? ans : -1;
}
# Verdict Execution time Memory Grader output
1 Correct 6 ms 5120 KB Output is correct
2 Correct 6 ms 5120 KB Output is correct
3 Correct 6 ms 5120 KB Output is correct
4 Correct 7 ms 5120 KB Output is correct
5 Correct 6 ms 5120 KB Output is correct
6 Correct 6 ms 5120 KB Output is correct
7 Correct 6 ms 5120 KB Output is correct
8 Correct 6 ms 5120 KB Output is correct
9 Correct 6 ms 5248 KB Output is correct
10 Correct 6 ms 5120 KB Output is correct
11 Correct 5 ms 5120 KB Output is correct
12 Correct 6 ms 5120 KB Output is correct
13 Correct 7 ms 5120 KB Output is correct
14 Correct 6 ms 5120 KB Output is correct
15 Correct 8 ms 5120 KB Output is correct
16 Correct 7 ms 5120 KB Output is correct
17 Correct 6 ms 5120 KB Output is correct
18 Correct 6 ms 5120 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 5120 KB Output is correct
2 Correct 6 ms 5120 KB Output is correct
3 Correct 6 ms 5120 KB Output is correct
4 Correct 7 ms 5120 KB Output is correct
5 Correct 6 ms 5120 KB Output is correct
6 Correct 6 ms 5120 KB Output is correct
7 Correct 6 ms 5120 KB Output is correct
8 Correct 6 ms 5120 KB Output is correct
9 Correct 6 ms 5248 KB Output is correct
10 Correct 6 ms 5120 KB Output is correct
11 Correct 5 ms 5120 KB Output is correct
12 Correct 6 ms 5120 KB Output is correct
13 Correct 7 ms 5120 KB Output is correct
14 Correct 6 ms 5120 KB Output is correct
15 Correct 8 ms 5120 KB Output is correct
16 Correct 7 ms 5120 KB Output is correct
17 Correct 6 ms 5120 KB Output is correct
18 Correct 6 ms 5120 KB Output is correct
19 Correct 6 ms 5120 KB Output is correct
20 Correct 13 ms 5120 KB Output is correct
21 Correct 7 ms 5248 KB Output is correct
22 Correct 8 ms 5248 KB Output is correct
23 Correct 8 ms 5248 KB Output is correct
24 Correct 7 ms 5248 KB Output is correct
25 Correct 7 ms 5248 KB Output is correct
26 Correct 8 ms 5248 KB Output is correct
27 Correct 7 ms 5248 KB Output is correct
28 Correct 7 ms 5248 KB Output is correct
29 Correct 7 ms 5376 KB Output is correct
30 Correct 7 ms 5248 KB Output is correct
31 Correct 8 ms 5248 KB Output is correct
32 Correct 8 ms 5248 KB Output is correct
33 Correct 8 ms 5248 KB Output is correct
34 Correct 7 ms 5248 KB Output is correct
35 Correct 7 ms 5248 KB Output is correct
36 Correct 6 ms 5248 KB Output is correct
37 Correct 7 ms 5248 KB Output is correct
38 Correct 7 ms 5248 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 5120 KB Output is correct
2 Correct 6 ms 5120 KB Output is correct
3 Correct 6 ms 5120 KB Output is correct
4 Correct 7 ms 5120 KB Output is correct
5 Correct 6 ms 5120 KB Output is correct
6 Correct 6 ms 5120 KB Output is correct
7 Correct 6 ms 5120 KB Output is correct
8 Correct 6 ms 5120 KB Output is correct
9 Correct 6 ms 5248 KB Output is correct
10 Correct 6 ms 5120 KB Output is correct
11 Correct 5 ms 5120 KB Output is correct
12 Correct 6 ms 5120 KB Output is correct
13 Correct 7 ms 5120 KB Output is correct
14 Correct 6 ms 5120 KB Output is correct
15 Correct 8 ms 5120 KB Output is correct
16 Correct 7 ms 5120 KB Output is correct
17 Correct 6 ms 5120 KB Output is correct
18 Correct 6 ms 5120 KB Output is correct
19 Correct 202 ms 13944 KB Output is correct
20 Correct 202 ms 14044 KB Output is correct
21 Correct 199 ms 14072 KB Output is correct
22 Correct 196 ms 14200 KB Output is correct
23 Correct 300 ms 14456 KB Output is correct
24 Correct 225 ms 14328 KB Output is correct
25 Correct 127 ms 25464 KB Output is correct
26 Correct 68 ms 26068 KB Output is correct
27 Incorrect 139 ms 17856 KB Output isn't correct
28 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 6 ms 5120 KB Output is correct
2 Correct 6 ms 5120 KB Output is correct
3 Correct 6 ms 5120 KB Output is correct
4 Correct 7 ms 5120 KB Output is correct
5 Correct 6 ms 5120 KB Output is correct
6 Correct 6 ms 5120 KB Output is correct
7 Correct 6 ms 5120 KB Output is correct
8 Correct 6 ms 5120 KB Output is correct
9 Correct 6 ms 5248 KB Output is correct
10 Correct 6 ms 5120 KB Output is correct
11 Correct 5 ms 5120 KB Output is correct
12 Correct 6 ms 5120 KB Output is correct
13 Correct 7 ms 5120 KB Output is correct
14 Correct 6 ms 5120 KB Output is correct
15 Correct 8 ms 5120 KB Output is correct
16 Correct 7 ms 5120 KB Output is correct
17 Correct 6 ms 5120 KB Output is correct
18 Correct 6 ms 5120 KB Output is correct
19 Correct 6 ms 5120 KB Output is correct
20 Correct 13 ms 5120 KB Output is correct
21 Correct 7 ms 5248 KB Output is correct
22 Correct 8 ms 5248 KB Output is correct
23 Correct 8 ms 5248 KB Output is correct
24 Correct 7 ms 5248 KB Output is correct
25 Correct 7 ms 5248 KB Output is correct
26 Correct 8 ms 5248 KB Output is correct
27 Correct 7 ms 5248 KB Output is correct
28 Correct 7 ms 5248 KB Output is correct
29 Correct 7 ms 5376 KB Output is correct
30 Correct 7 ms 5248 KB Output is correct
31 Correct 8 ms 5248 KB Output is correct
32 Correct 8 ms 5248 KB Output is correct
33 Correct 8 ms 5248 KB Output is correct
34 Correct 7 ms 5248 KB Output is correct
35 Correct 7 ms 5248 KB Output is correct
36 Correct 6 ms 5248 KB Output is correct
37 Correct 7 ms 5248 KB Output is correct
38 Correct 7 ms 5248 KB Output is correct
39 Correct 202 ms 13944 KB Output is correct
40 Correct 202 ms 14044 KB Output is correct
41 Correct 199 ms 14072 KB Output is correct
42 Correct 196 ms 14200 KB Output is correct
43 Correct 300 ms 14456 KB Output is correct
44 Correct 225 ms 14328 KB Output is correct
45 Correct 127 ms 25464 KB Output is correct
46 Correct 68 ms 26068 KB Output is correct
47 Incorrect 139 ms 17856 KB Output isn't correct
48 Halted 0 ms 0 KB -