Submission #58780

# Submission time Handle Problem Language Result Execution time Memory
58780 2018-07-19T10:38:59 Z Sherazin Race (IOI11_race) C++14
31 / 100
757 ms 55844 KB
//#include "race.h"
#include <bits/stdc++.h>

#define pii pair<int, int>
#define x first
#define y second

using namespace std;

const int N = 2e5 + 5;
const int M = 5e5 + 5;

int n, k;
int ans = -1, centroid, mxnode, cnt = 0;
int dep[N], path[M], dp[M];
vector<vector<pii> > g(N);
bitset<N> chk;

int subtree(int u, int p) {
	dep[u] = 1;
	for(pii v : g[u]) if(!chk[v.x] && v.x != p) {
		dep[u] += subtree(v.x, u);
	}
	return dep[u];
}

void centdecomp(int u, int p, int all) {
	int ret = all - dep[u];
	for(pii v : g[u]) if(!chk[v.x] && v.x != p) {
		centdecomp(v.x, u, all);
		ret = max(ret, dep[v.x]);
	}
	if(ret < mxnode) centroid = u, mxnode = ret;
}

void dfs(int u, int p, int cost, int edge, bool fill) {
	if(cost > k) return;
	if(!fill) {
		if(dp[k - cost] == cnt && (edge + path[k - cost] < ans || ans == -1)) ans = edge + path[k - cost];
		if(cost == k && (edge < ans || ans == -1)) ans = edge;
	} else if(dp[cost] < cnt || edge < path[cost]) dp[cost] = cnt, path[cost] = edge;

	for(pii v : g[u]) if(!chk[v.x] && v.x != p) {
		dfs(v.x, u, cost + v.y, edge + 1, fill);
	}
}

void proc(int u) {
	cnt++;
	if(subtree(u, -1) <= 1) return;
	mxnode = dep[u] + 1;
	centdecomp(u, -1, dep[u]);
	for(pii v : g[centroid]) if(!chk[v.x]) {
		dfs(v.x, centroid, v.y, 1, false);
		dfs(v.x, centroid, v.y, 1, true);
	}
	chk[centroid] = 1;
	for(pii v : g[centroid]) if(!chk[v.x]) {
		proc(v.x);
	}
}

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]);
	}

	proc(0);

	return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 9 ms 4984 KB Output is correct
2 Correct 8 ms 5220 KB Output is correct
3 Correct 7 ms 5220 KB Output is correct
4 Correct 7 ms 5220 KB Output is correct
5 Correct 8 ms 5324 KB Output is correct
6 Correct 8 ms 5324 KB Output is correct
7 Correct 8 ms 5364 KB Output is correct
8 Correct 10 ms 5384 KB Output is correct
9 Correct 8 ms 5384 KB Output is correct
10 Correct 9 ms 5392 KB Output is correct
11 Correct 9 ms 5524 KB Output is correct
12 Correct 7 ms 5524 KB Output is correct
13 Correct 8 ms 5524 KB Output is correct
14 Correct 7 ms 5524 KB Output is correct
15 Correct 7 ms 5524 KB Output is correct
16 Correct 8 ms 5524 KB Output is correct
17 Correct 8 ms 5524 KB Output is correct
18 Correct 7 ms 5524 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 4984 KB Output is correct
2 Correct 8 ms 5220 KB Output is correct
3 Correct 7 ms 5220 KB Output is correct
4 Correct 7 ms 5220 KB Output is correct
5 Correct 8 ms 5324 KB Output is correct
6 Correct 8 ms 5324 KB Output is correct
7 Correct 8 ms 5364 KB Output is correct
8 Correct 10 ms 5384 KB Output is correct
9 Correct 8 ms 5384 KB Output is correct
10 Correct 9 ms 5392 KB Output is correct
11 Correct 9 ms 5524 KB Output is correct
12 Correct 7 ms 5524 KB Output is correct
13 Correct 8 ms 5524 KB Output is correct
14 Correct 7 ms 5524 KB Output is correct
15 Correct 7 ms 5524 KB Output is correct
16 Correct 8 ms 5524 KB Output is correct
17 Correct 8 ms 5524 KB Output is correct
18 Correct 7 ms 5524 KB Output is correct
19 Correct 7 ms 5524 KB Output is correct
20 Correct 8 ms 5524 KB Output is correct
21 Correct 10 ms 5528 KB Output is correct
22 Runtime error 15 ms 10532 KB Execution killed with signal 11 (could be triggered by violating memory limits)
23 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 9 ms 4984 KB Output is correct
2 Correct 8 ms 5220 KB Output is correct
3 Correct 7 ms 5220 KB Output is correct
4 Correct 7 ms 5220 KB Output is correct
5 Correct 8 ms 5324 KB Output is correct
6 Correct 8 ms 5324 KB Output is correct
7 Correct 8 ms 5364 KB Output is correct
8 Correct 10 ms 5384 KB Output is correct
9 Correct 8 ms 5384 KB Output is correct
10 Correct 9 ms 5392 KB Output is correct
11 Correct 9 ms 5524 KB Output is correct
12 Correct 7 ms 5524 KB Output is correct
13 Correct 8 ms 5524 KB Output is correct
14 Correct 7 ms 5524 KB Output is correct
15 Correct 7 ms 5524 KB Output is correct
16 Correct 8 ms 5524 KB Output is correct
17 Correct 8 ms 5524 KB Output is correct
18 Correct 7 ms 5524 KB Output is correct
19 Correct 379 ms 17216 KB Output is correct
20 Correct 284 ms 18528 KB Output is correct
21 Correct 351 ms 19872 KB Output is correct
22 Correct 324 ms 21380 KB Output is correct
23 Correct 217 ms 22892 KB Output is correct
24 Correct 146 ms 24124 KB Output is correct
25 Correct 361 ms 29128 KB Output is correct
26 Correct 172 ms 34128 KB Output is correct
27 Correct 334 ms 35152 KB Output is correct
28 Correct 726 ms 52568 KB Output is correct
29 Correct 757 ms 54520 KB Output is correct
30 Correct 378 ms 54520 KB Output is correct
31 Correct 366 ms 54520 KB Output is correct
32 Correct 434 ms 54520 KB Output is correct
33 Correct 684 ms 54520 KB Output is correct
34 Correct 433 ms 55844 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 4984 KB Output is correct
2 Correct 8 ms 5220 KB Output is correct
3 Correct 7 ms 5220 KB Output is correct
4 Correct 7 ms 5220 KB Output is correct
5 Correct 8 ms 5324 KB Output is correct
6 Correct 8 ms 5324 KB Output is correct
7 Correct 8 ms 5364 KB Output is correct
8 Correct 10 ms 5384 KB Output is correct
9 Correct 8 ms 5384 KB Output is correct
10 Correct 9 ms 5392 KB Output is correct
11 Correct 9 ms 5524 KB Output is correct
12 Correct 7 ms 5524 KB Output is correct
13 Correct 8 ms 5524 KB Output is correct
14 Correct 7 ms 5524 KB Output is correct
15 Correct 7 ms 5524 KB Output is correct
16 Correct 8 ms 5524 KB Output is correct
17 Correct 8 ms 5524 KB Output is correct
18 Correct 7 ms 5524 KB Output is correct
19 Correct 7 ms 5524 KB Output is correct
20 Correct 8 ms 5524 KB Output is correct
21 Correct 10 ms 5528 KB Output is correct
22 Runtime error 15 ms 10532 KB Execution killed with signal 11 (could be triggered by violating memory limits)
23 Halted 0 ms 0 KB -