Submission #62073

# Submission time Handle Problem Language Result Execution time Memory
62073 2018-07-27T11:54:13 Z aome Race (IOI11_race) C++17
100 / 100
1357 ms 85548 KB
#include "race.h"

#include <bits/stdc++.h>

using namespace std;

const int N = 200005;
const int M = 1000005;
const int INF = 0x3f3f3f3f;

int K;
int res = INF;
int sz[N], h[N];
int f[M];
long long d[N];
bool del[N];
vector<int> buf;
vector< pair<int, int> > G[N];

void add(int u, int v, int w) {
	G[u].push_back({v, w});
	G[v].push_back({u, w});
}

void dfs(int u, int p) {
	sz[u] = 1;
	buf.push_back(u);
	for (auto v : G[u]) {
		if (p == v.first || del[v.first]) continue;
		dfs(v.first, u), sz[u] += sz[v.first];
	}
}

int find(int u, int p, int r) {
	for (auto v : G[u]) {
		if (p == v.first || del[v.first]) continue;
		if (2 * sz[v.first] >= sz[r]) return find(v.first, u, r);
	}
	return u;
}

void query(int u, int p) {
	if (d[u] <= K) res = min(res, h[u] + f[K - d[u]]);
	for (auto v : G[u]) {
		if (p == v.first || del[v.first]) continue;
		h[v.first] = h[u] + 1, d[v.first] = d[u] + v.second;
		query(v.first, u);
	}
}

void add(int u, int p) {
	if (d[u] <= K) f[d[u]] = min(f[d[u]], h[u]);
	for (auto v : G[u]) {
		if (p == v.first || del[v.first]) continue;
		add(v.first, u);
	}
}

void solve(int u) {
	buf.clear(), dfs(u, u);
	u = find(u, u, u), del[u] = 1;
	d[u] = h[u] = f[0] = 0;
	for (auto v : G[u]) {
		if (del[v.first]) continue;
		d[v.first] = v.second, h[v.first] = 1;
		query(v.first, u), add(v.first, u);
	}
	for (auto i : buf) {
		if (d[i] <= K) f[d[i]] = INF;
	}
	for (auto v : G[u]) {
		if (del[v.first]) continue; solve(v.first);
	}
}

int best_path(int n, int _K, int H[][2], int L[]) {
	K = _K;
	for (int i = 0; i < (n - 1); ++i) {
		add(H[i][0], H[i][1], L[i]);
	}
	memset(f, INF, sizeof f);
	solve(0);
	return res == INF ? -1 : res;
}

Compilation message

race.cpp: In function 'void solve(int)':
race.cpp:72:3: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
   if (del[v.first]) continue; solve(v.first);
   ^~
race.cpp:72:31: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
   if (del[v.first]) continue; solve(v.first);
                               ^~~~~
# Verdict Execution time Memory Grader output
1 Correct 10 ms 8952 KB Output is correct
2 Correct 11 ms 9060 KB Output is correct
3 Correct 9 ms 9060 KB Output is correct
4 Correct 13 ms 9172 KB Output is correct
5 Correct 11 ms 9172 KB Output is correct
6 Correct 13 ms 9172 KB Output is correct
7 Correct 11 ms 9172 KB Output is correct
8 Correct 10 ms 9172 KB Output is correct
9 Correct 11 ms 9172 KB Output is correct
10 Correct 10 ms 9172 KB Output is correct
11 Correct 10 ms 9272 KB Output is correct
12 Correct 11 ms 9272 KB Output is correct
13 Correct 10 ms 9272 KB Output is correct
14 Correct 14 ms 9272 KB Output is correct
15 Correct 10 ms 9272 KB Output is correct
16 Correct 10 ms 9272 KB Output is correct
17 Correct 12 ms 9272 KB Output is correct
18 Correct 10 ms 9272 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 8952 KB Output is correct
2 Correct 11 ms 9060 KB Output is correct
3 Correct 9 ms 9060 KB Output is correct
4 Correct 13 ms 9172 KB Output is correct
5 Correct 11 ms 9172 KB Output is correct
6 Correct 13 ms 9172 KB Output is correct
7 Correct 11 ms 9172 KB Output is correct
8 Correct 10 ms 9172 KB Output is correct
9 Correct 11 ms 9172 KB Output is correct
10 Correct 10 ms 9172 KB Output is correct
11 Correct 10 ms 9272 KB Output is correct
12 Correct 11 ms 9272 KB Output is correct
13 Correct 10 ms 9272 KB Output is correct
14 Correct 14 ms 9272 KB Output is correct
15 Correct 10 ms 9272 KB Output is correct
16 Correct 10 ms 9272 KB Output is correct
17 Correct 12 ms 9272 KB Output is correct
18 Correct 10 ms 9272 KB Output is correct
19 Correct 10 ms 9272 KB Output is correct
20 Correct 10 ms 9272 KB Output is correct
21 Correct 12 ms 9296 KB Output is correct
22 Correct 11 ms 9296 KB Output is correct
23 Correct 12 ms 9296 KB Output is correct
24 Correct 11 ms 9296 KB Output is correct
25 Correct 11 ms 9296 KB Output is correct
26 Correct 10 ms 9296 KB Output is correct
27 Correct 12 ms 9296 KB Output is correct
28 Correct 12 ms 9296 KB Output is correct
29 Correct 13 ms 9324 KB Output is correct
30 Correct 15 ms 9324 KB Output is correct
31 Correct 12 ms 9324 KB Output is correct
32 Correct 13 ms 9324 KB Output is correct
33 Correct 13 ms 9324 KB Output is correct
34 Correct 12 ms 9324 KB Output is correct
35 Correct 11 ms 9324 KB Output is correct
36 Correct 12 ms 9328 KB Output is correct
37 Correct 12 ms 9328 KB Output is correct
38 Correct 11 ms 9328 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 8952 KB Output is correct
2 Correct 11 ms 9060 KB Output is correct
3 Correct 9 ms 9060 KB Output is correct
4 Correct 13 ms 9172 KB Output is correct
5 Correct 11 ms 9172 KB Output is correct
6 Correct 13 ms 9172 KB Output is correct
7 Correct 11 ms 9172 KB Output is correct
8 Correct 10 ms 9172 KB Output is correct
9 Correct 11 ms 9172 KB Output is correct
10 Correct 10 ms 9172 KB Output is correct
11 Correct 10 ms 9272 KB Output is correct
12 Correct 11 ms 9272 KB Output is correct
13 Correct 10 ms 9272 KB Output is correct
14 Correct 14 ms 9272 KB Output is correct
15 Correct 10 ms 9272 KB Output is correct
16 Correct 10 ms 9272 KB Output is correct
17 Correct 12 ms 9272 KB Output is correct
18 Correct 10 ms 9272 KB Output is correct
19 Correct 383 ms 16232 KB Output is correct
20 Correct 409 ms 16232 KB Output is correct
21 Correct 409 ms 16232 KB Output is correct
22 Correct 241 ms 16356 KB Output is correct
23 Correct 317 ms 16476 KB Output is correct
24 Correct 159 ms 16476 KB Output is correct
25 Correct 442 ms 19048 KB Output is correct
26 Correct 123 ms 21992 KB Output is correct
27 Correct 318 ms 23268 KB Output is correct
28 Correct 1219 ms 37884 KB Output is correct
29 Correct 1004 ms 39988 KB Output is correct
30 Correct 330 ms 39988 KB Output is correct
31 Correct 353 ms 39988 KB Output is correct
32 Correct 532 ms 39988 KB Output is correct
33 Correct 851 ms 40388 KB Output is correct
34 Correct 779 ms 44084 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 8952 KB Output is correct
2 Correct 11 ms 9060 KB Output is correct
3 Correct 9 ms 9060 KB Output is correct
4 Correct 13 ms 9172 KB Output is correct
5 Correct 11 ms 9172 KB Output is correct
6 Correct 13 ms 9172 KB Output is correct
7 Correct 11 ms 9172 KB Output is correct
8 Correct 10 ms 9172 KB Output is correct
9 Correct 11 ms 9172 KB Output is correct
10 Correct 10 ms 9172 KB Output is correct
11 Correct 10 ms 9272 KB Output is correct
12 Correct 11 ms 9272 KB Output is correct
13 Correct 10 ms 9272 KB Output is correct
14 Correct 14 ms 9272 KB Output is correct
15 Correct 10 ms 9272 KB Output is correct
16 Correct 10 ms 9272 KB Output is correct
17 Correct 12 ms 9272 KB Output is correct
18 Correct 10 ms 9272 KB Output is correct
19 Correct 10 ms 9272 KB Output is correct
20 Correct 10 ms 9272 KB Output is correct
21 Correct 12 ms 9296 KB Output is correct
22 Correct 11 ms 9296 KB Output is correct
23 Correct 12 ms 9296 KB Output is correct
24 Correct 11 ms 9296 KB Output is correct
25 Correct 11 ms 9296 KB Output is correct
26 Correct 10 ms 9296 KB Output is correct
27 Correct 12 ms 9296 KB Output is correct
28 Correct 12 ms 9296 KB Output is correct
29 Correct 13 ms 9324 KB Output is correct
30 Correct 15 ms 9324 KB Output is correct
31 Correct 12 ms 9324 KB Output is correct
32 Correct 13 ms 9324 KB Output is correct
33 Correct 13 ms 9324 KB Output is correct
34 Correct 12 ms 9324 KB Output is correct
35 Correct 11 ms 9324 KB Output is correct
36 Correct 12 ms 9328 KB Output is correct
37 Correct 12 ms 9328 KB Output is correct
38 Correct 11 ms 9328 KB Output is correct
39 Correct 383 ms 16232 KB Output is correct
40 Correct 409 ms 16232 KB Output is correct
41 Correct 409 ms 16232 KB Output is correct
42 Correct 241 ms 16356 KB Output is correct
43 Correct 317 ms 16476 KB Output is correct
44 Correct 159 ms 16476 KB Output is correct
45 Correct 442 ms 19048 KB Output is correct
46 Correct 123 ms 21992 KB Output is correct
47 Correct 318 ms 23268 KB Output is correct
48 Correct 1219 ms 37884 KB Output is correct
49 Correct 1004 ms 39988 KB Output is correct
50 Correct 330 ms 39988 KB Output is correct
51 Correct 353 ms 39988 KB Output is correct
52 Correct 532 ms 39988 KB Output is correct
53 Correct 851 ms 40388 KB Output is correct
54 Correct 779 ms 44084 KB Output is correct
55 Correct 25 ms 44084 KB Output is correct
56 Correct 26 ms 44084 KB Output is correct
57 Correct 166 ms 44084 KB Output is correct
58 Correct 68 ms 44084 KB Output is correct
59 Correct 154 ms 47860 KB Output is correct
60 Correct 1191 ms 62796 KB Output is correct
61 Correct 334 ms 62796 KB Output is correct
62 Correct 341 ms 62796 KB Output is correct
63 Correct 445 ms 62796 KB Output is correct
64 Correct 1057 ms 64548 KB Output is correct
65 Correct 807 ms 68556 KB Output is correct
66 Correct 1357 ms 80092 KB Output is correct
67 Correct 330 ms 80092 KB Output is correct
68 Correct 496 ms 80092 KB Output is correct
69 Correct 637 ms 82760 KB Output is correct
70 Correct 542 ms 85548 KB Output is correct