Submission #62072

# Submission time Handle Problem Language Result Execution time Memory
62072 2018-07-27T11:53:43 Z aome Race (IOI11_race) C++17
21 / 100
404 ms 49180 KB
#include "race.h"

#include <bits/stdc++.h>

using namespace std;

const int N = 100005;
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 7 ms 6520 KB Output is correct
2 Correct 9 ms 6628 KB Output is correct
3 Correct 9 ms 6668 KB Output is correct
4 Correct 10 ms 6740 KB Output is correct
5 Correct 9 ms 6740 KB Output is correct
6 Correct 10 ms 6740 KB Output is correct
7 Correct 7 ms 6740 KB Output is correct
8 Correct 9 ms 6740 KB Output is correct
9 Correct 9 ms 6800 KB Output is correct
10 Correct 10 ms 6856 KB Output is correct
11 Correct 11 ms 6856 KB Output is correct
12 Correct 9 ms 6864 KB Output is correct
13 Correct 10 ms 7012 KB Output is correct
14 Correct 8 ms 7036 KB Output is correct
15 Correct 9 ms 7036 KB Output is correct
16 Correct 13 ms 7044 KB Output is correct
17 Correct 8 ms 7048 KB Output is correct
18 Correct 10 ms 7052 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 6520 KB Output is correct
2 Correct 9 ms 6628 KB Output is correct
3 Correct 9 ms 6668 KB Output is correct
4 Correct 10 ms 6740 KB Output is correct
5 Correct 9 ms 6740 KB Output is correct
6 Correct 10 ms 6740 KB Output is correct
7 Correct 7 ms 6740 KB Output is correct
8 Correct 9 ms 6740 KB Output is correct
9 Correct 9 ms 6800 KB Output is correct
10 Correct 10 ms 6856 KB Output is correct
11 Correct 11 ms 6856 KB Output is correct
12 Correct 9 ms 6864 KB Output is correct
13 Correct 10 ms 7012 KB Output is correct
14 Correct 8 ms 7036 KB Output is correct
15 Correct 9 ms 7036 KB Output is correct
16 Correct 13 ms 7044 KB Output is correct
17 Correct 8 ms 7048 KB Output is correct
18 Correct 10 ms 7052 KB Output is correct
19 Correct 9 ms 7184 KB Output is correct
20 Correct 9 ms 7184 KB Output is correct
21 Correct 8 ms 7184 KB Output is correct
22 Correct 10 ms 7240 KB Output is correct
23 Correct 9 ms 7240 KB Output is correct
24 Correct 11 ms 7240 KB Output is correct
25 Correct 10 ms 7240 KB Output is correct
26 Correct 11 ms 7264 KB Output is correct
27 Correct 12 ms 7296 KB Output is correct
28 Correct 13 ms 7312 KB Output is correct
29 Correct 8 ms 7328 KB Output is correct
30 Correct 12 ms 7360 KB Output is correct
31 Correct 12 ms 7408 KB Output is correct
32 Correct 11 ms 7408 KB Output is correct
33 Correct 12 ms 7436 KB Output is correct
34 Correct 10 ms 7484 KB Output is correct
35 Correct 11 ms 7484 KB Output is correct
36 Correct 12 ms 7548 KB Output is correct
37 Correct 12 ms 7548 KB Output is correct
38 Correct 12 ms 7548 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 6520 KB Output is correct
2 Correct 9 ms 6628 KB Output is correct
3 Correct 9 ms 6668 KB Output is correct
4 Correct 10 ms 6740 KB Output is correct
5 Correct 9 ms 6740 KB Output is correct
6 Correct 10 ms 6740 KB Output is correct
7 Correct 7 ms 6740 KB Output is correct
8 Correct 9 ms 6740 KB Output is correct
9 Correct 9 ms 6800 KB Output is correct
10 Correct 10 ms 6856 KB Output is correct
11 Correct 11 ms 6856 KB Output is correct
12 Correct 9 ms 6864 KB Output is correct
13 Correct 10 ms 7012 KB Output is correct
14 Correct 8 ms 7036 KB Output is correct
15 Correct 9 ms 7036 KB Output is correct
16 Correct 13 ms 7044 KB Output is correct
17 Correct 8 ms 7048 KB Output is correct
18 Correct 10 ms 7052 KB Output is correct
19 Correct 403 ms 15860 KB Output is correct
20 Correct 404 ms 17156 KB Output is correct
21 Correct 346 ms 18488 KB Output is correct
22 Correct 270 ms 20004 KB Output is correct
23 Correct 272 ms 21644 KB Output is correct
24 Correct 178 ms 22956 KB Output is correct
25 Correct 387 ms 26916 KB Output is correct
26 Correct 148 ms 31244 KB Output is correct
27 Runtime error 180 ms 49180 KB Execution killed with signal 11 (could be triggered by violating memory limits)
28 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 7 ms 6520 KB Output is correct
2 Correct 9 ms 6628 KB Output is correct
3 Correct 9 ms 6668 KB Output is correct
4 Correct 10 ms 6740 KB Output is correct
5 Correct 9 ms 6740 KB Output is correct
6 Correct 10 ms 6740 KB Output is correct
7 Correct 7 ms 6740 KB Output is correct
8 Correct 9 ms 6740 KB Output is correct
9 Correct 9 ms 6800 KB Output is correct
10 Correct 10 ms 6856 KB Output is correct
11 Correct 11 ms 6856 KB Output is correct
12 Correct 9 ms 6864 KB Output is correct
13 Correct 10 ms 7012 KB Output is correct
14 Correct 8 ms 7036 KB Output is correct
15 Correct 9 ms 7036 KB Output is correct
16 Correct 13 ms 7044 KB Output is correct
17 Correct 8 ms 7048 KB Output is correct
18 Correct 10 ms 7052 KB Output is correct
19 Correct 9 ms 7184 KB Output is correct
20 Correct 9 ms 7184 KB Output is correct
21 Correct 8 ms 7184 KB Output is correct
22 Correct 10 ms 7240 KB Output is correct
23 Correct 9 ms 7240 KB Output is correct
24 Correct 11 ms 7240 KB Output is correct
25 Correct 10 ms 7240 KB Output is correct
26 Correct 11 ms 7264 KB Output is correct
27 Correct 12 ms 7296 KB Output is correct
28 Correct 13 ms 7312 KB Output is correct
29 Correct 8 ms 7328 KB Output is correct
30 Correct 12 ms 7360 KB Output is correct
31 Correct 12 ms 7408 KB Output is correct
32 Correct 11 ms 7408 KB Output is correct
33 Correct 12 ms 7436 KB Output is correct
34 Correct 10 ms 7484 KB Output is correct
35 Correct 11 ms 7484 KB Output is correct
36 Correct 12 ms 7548 KB Output is correct
37 Correct 12 ms 7548 KB Output is correct
38 Correct 12 ms 7548 KB Output is correct
39 Correct 403 ms 15860 KB Output is correct
40 Correct 404 ms 17156 KB Output is correct
41 Correct 346 ms 18488 KB Output is correct
42 Correct 270 ms 20004 KB Output is correct
43 Correct 272 ms 21644 KB Output is correct
44 Correct 178 ms 22956 KB Output is correct
45 Correct 387 ms 26916 KB Output is correct
46 Correct 148 ms 31244 KB Output is correct
47 Runtime error 180 ms 49180 KB Execution killed with signal 11 (could be triggered by violating memory limits)
48 Halted 0 ms 0 KB -