Submission #758587

# Submission time Handle Problem Language Result Execution time Memory
758587 2023-06-14T23:40:30 Z KN200711 Race (IOI11_race) C++14
100 / 100
433 ms 111124 KB
#include "race.h"
# include <bits/stdc++.h>
# define ll long long
# define fi first
# define se second
using namespace std;

set< pair<ll, int> > nw[200001];
vector< pair<ll, int> > edge[200001];
int ans = 1e9 + 11;
int KK;

void dfs(int a, int pr, ll v, int c) {
	nw[a].insert(make_pair(v, c));
	for(int k=0;k<edge[a].size();k++) {
		if(edge[a][k].fi == pr) continue;
		dfs(edge[a][k].fi, a, v + edge[a][k].se, c+1);
		if(nw[edge[a][k].fi].size() > nw[a].size()) swap(nw[a], nw[edge[a][k].fi]);
		for(auto p : nw[edge[a][k].fi]) {
			auto it = nw[a].lower_bound(make_pair(KK + 2ll * v - p.fi, 0));
			if(it == nw[a].end()) continue;
			if(it->fi == KK + 2ll * v - p.fi) ans = min(ans, it->se + p.se - 2 * c);
		}
		for(auto p : nw[edge[a][k].fi]) {
			nw[a].insert(p);
		}
	}
}

int best_path(int N, int K, int H[][2], int L[]) {
	KK = K;
	for(int i=0;i<N;i++) {
		edge[i].clear();
		nw[i].clear();
	}
	for(int i=0;i<N-1;i++) {
		edge[H[i][0]].push_back(make_pair(H[i][1], L[i]));
		edge[H[i][1]].push_back(make_pair(H[i][0], L[i]));
	}
	ans = 1e9 + 11;
	dfs(0, -1, 0, 0);
	if(ans == 1e9 + 11) return -1;
	return ans;
}

Compilation message

race.cpp: In function 'void dfs(int, int, long long int, int)':
race.cpp:15:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   15 |  for(int k=0;k<edge[a].size();k++) {
      |              ~^~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 7 ms 14420 KB Output is correct
2 Correct 7 ms 14420 KB Output is correct
3 Correct 8 ms 14420 KB Output is correct
4 Correct 8 ms 14344 KB Output is correct
5 Correct 8 ms 14420 KB Output is correct
6 Correct 7 ms 14368 KB Output is correct
7 Correct 8 ms 14420 KB Output is correct
8 Correct 8 ms 14420 KB Output is correct
9 Correct 9 ms 14420 KB Output is correct
10 Correct 10 ms 14420 KB Output is correct
11 Correct 7 ms 14428 KB Output is correct
12 Correct 10 ms 14328 KB Output is correct
13 Correct 8 ms 14356 KB Output is correct
14 Correct 11 ms 14396 KB Output is correct
15 Correct 8 ms 14400 KB Output is correct
16 Correct 8 ms 14420 KB Output is correct
17 Correct 11 ms 14420 KB Output is correct
18 Correct 8 ms 14400 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 14420 KB Output is correct
2 Correct 7 ms 14420 KB Output is correct
3 Correct 8 ms 14420 KB Output is correct
4 Correct 8 ms 14344 KB Output is correct
5 Correct 8 ms 14420 KB Output is correct
6 Correct 7 ms 14368 KB Output is correct
7 Correct 8 ms 14420 KB Output is correct
8 Correct 8 ms 14420 KB Output is correct
9 Correct 9 ms 14420 KB Output is correct
10 Correct 10 ms 14420 KB Output is correct
11 Correct 7 ms 14428 KB Output is correct
12 Correct 10 ms 14328 KB Output is correct
13 Correct 8 ms 14356 KB Output is correct
14 Correct 11 ms 14396 KB Output is correct
15 Correct 8 ms 14400 KB Output is correct
16 Correct 8 ms 14420 KB Output is correct
17 Correct 11 ms 14420 KB Output is correct
18 Correct 8 ms 14400 KB Output is correct
19 Correct 8 ms 14404 KB Output is correct
20 Correct 9 ms 14368 KB Output is correct
21 Correct 9 ms 14676 KB Output is correct
22 Correct 13 ms 14664 KB Output is correct
23 Correct 11 ms 14684 KB Output is correct
24 Correct 11 ms 14644 KB Output is correct
25 Correct 9 ms 14668 KB Output is correct
26 Correct 11 ms 14676 KB Output is correct
27 Correct 10 ms 14548 KB Output is correct
28 Correct 12 ms 14676 KB Output is correct
29 Correct 10 ms 14676 KB Output is correct
30 Correct 9 ms 14676 KB Output is correct
31 Correct 11 ms 14668 KB Output is correct
32 Correct 10 ms 14676 KB Output is correct
33 Correct 10 ms 14684 KB Output is correct
34 Correct 11 ms 14676 KB Output is correct
35 Correct 11 ms 14664 KB Output is correct
36 Correct 9 ms 14676 KB Output is correct
37 Correct 9 ms 14536 KB Output is correct
38 Correct 9 ms 14676 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 14420 KB Output is correct
2 Correct 7 ms 14420 KB Output is correct
3 Correct 8 ms 14420 KB Output is correct
4 Correct 8 ms 14344 KB Output is correct
5 Correct 8 ms 14420 KB Output is correct
6 Correct 7 ms 14368 KB Output is correct
7 Correct 8 ms 14420 KB Output is correct
8 Correct 8 ms 14420 KB Output is correct
9 Correct 9 ms 14420 KB Output is correct
10 Correct 10 ms 14420 KB Output is correct
11 Correct 7 ms 14428 KB Output is correct
12 Correct 10 ms 14328 KB Output is correct
13 Correct 8 ms 14356 KB Output is correct
14 Correct 11 ms 14396 KB Output is correct
15 Correct 8 ms 14400 KB Output is correct
16 Correct 8 ms 14420 KB Output is correct
17 Correct 11 ms 14420 KB Output is correct
18 Correct 8 ms 14400 KB Output is correct
19 Correct 162 ms 42404 KB Output is correct
20 Correct 169 ms 42440 KB Output is correct
21 Correct 187 ms 41772 KB Output is correct
22 Correct 135 ms 40308 KB Output is correct
23 Correct 183 ms 54896 KB Output is correct
24 Correct 126 ms 40908 KB Output is correct
25 Correct 142 ms 47004 KB Output is correct
26 Correct 105 ms 52916 KB Output is correct
27 Correct 203 ms 52544 KB Output is correct
28 Correct 284 ms 91712 KB Output is correct
29 Correct 288 ms 89908 KB Output is correct
30 Correct 213 ms 52648 KB Output is correct
31 Correct 216 ms 52480 KB Output is correct
32 Correct 269 ms 52700 KB Output is correct
33 Correct 211 ms 54348 KB Output is correct
34 Correct 321 ms 87304 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 14420 KB Output is correct
2 Correct 7 ms 14420 KB Output is correct
3 Correct 8 ms 14420 KB Output is correct
4 Correct 8 ms 14344 KB Output is correct
5 Correct 8 ms 14420 KB Output is correct
6 Correct 7 ms 14368 KB Output is correct
7 Correct 8 ms 14420 KB Output is correct
8 Correct 8 ms 14420 KB Output is correct
9 Correct 9 ms 14420 KB Output is correct
10 Correct 10 ms 14420 KB Output is correct
11 Correct 7 ms 14428 KB Output is correct
12 Correct 10 ms 14328 KB Output is correct
13 Correct 8 ms 14356 KB Output is correct
14 Correct 11 ms 14396 KB Output is correct
15 Correct 8 ms 14400 KB Output is correct
16 Correct 8 ms 14420 KB Output is correct
17 Correct 11 ms 14420 KB Output is correct
18 Correct 8 ms 14400 KB Output is correct
19 Correct 8 ms 14404 KB Output is correct
20 Correct 9 ms 14368 KB Output is correct
21 Correct 9 ms 14676 KB Output is correct
22 Correct 13 ms 14664 KB Output is correct
23 Correct 11 ms 14684 KB Output is correct
24 Correct 11 ms 14644 KB Output is correct
25 Correct 9 ms 14668 KB Output is correct
26 Correct 11 ms 14676 KB Output is correct
27 Correct 10 ms 14548 KB Output is correct
28 Correct 12 ms 14676 KB Output is correct
29 Correct 10 ms 14676 KB Output is correct
30 Correct 9 ms 14676 KB Output is correct
31 Correct 11 ms 14668 KB Output is correct
32 Correct 10 ms 14676 KB Output is correct
33 Correct 10 ms 14684 KB Output is correct
34 Correct 11 ms 14676 KB Output is correct
35 Correct 11 ms 14664 KB Output is correct
36 Correct 9 ms 14676 KB Output is correct
37 Correct 9 ms 14536 KB Output is correct
38 Correct 9 ms 14676 KB Output is correct
39 Correct 162 ms 42404 KB Output is correct
40 Correct 169 ms 42440 KB Output is correct
41 Correct 187 ms 41772 KB Output is correct
42 Correct 135 ms 40308 KB Output is correct
43 Correct 183 ms 54896 KB Output is correct
44 Correct 126 ms 40908 KB Output is correct
45 Correct 142 ms 47004 KB Output is correct
46 Correct 105 ms 52916 KB Output is correct
47 Correct 203 ms 52544 KB Output is correct
48 Correct 284 ms 91712 KB Output is correct
49 Correct 288 ms 89908 KB Output is correct
50 Correct 213 ms 52648 KB Output is correct
51 Correct 216 ms 52480 KB Output is correct
52 Correct 269 ms 52700 KB Output is correct
53 Correct 211 ms 54348 KB Output is correct
54 Correct 321 ms 87304 KB Output is correct
55 Correct 22 ms 17876 KB Output is correct
56 Correct 16 ms 16596 KB Output is correct
57 Correct 99 ms 37348 KB Output is correct
58 Correct 51 ms 27564 KB Output is correct
59 Correct 78 ms 52832 KB Output is correct
60 Correct 275 ms 90312 KB Output is correct
61 Correct 257 ms 58304 KB Output is correct
62 Correct 204 ms 52608 KB Output is correct
63 Correct 253 ms 52704 KB Output is correct
64 Correct 433 ms 111124 KB Output is correct
65 Correct 404 ms 102616 KB Output is correct
66 Correct 277 ms 85836 KB Output is correct
67 Correct 179 ms 42352 KB Output is correct
68 Correct 315 ms 67596 KB Output is correct
69 Correct 346 ms 73072 KB Output is correct
70 Correct 288 ms 65248 KB Output is correct