Submission #38931

# Submission time Handle Problem Language Result Execution time Memory
38931 2018-01-08T06:40:53 Z 14kg Race (IOI11_race) C++11
100 / 100
1293 ms 65984 KB
#include "race.h"
#include <vector>
#include <algorithm>
#include <set>
#define N 200001
#define M 1000001
#define INF 999999999
#define min2(x,y) (x<y?x:y)

using namespace std;
int n, m, out=INF;
vector<pair<int, long long> > r[N];
set<int> prohibit[N];

int len, core, d_cnt[N];
pair<int,int> d[M];
bool check[N];

bool check_can(int x, int y) {
	set<int>::iterator it = prohibit[x].lower_bound(y);

	if (it == prohibit[x].end() || *it != y) return true;
	return false;
}
void find_len(int x) {
	check[x] = true, len++;
	for (auto i : r[x])
		if (check[i.first] == false && check_can(x, i.first)) find_len(i.first);
}
int find_cnt(int x, int up) {
	d_cnt[x] = 1, check[x] = false;
	for (auto i : r[x])
		if (i.first != up && check_can(x, i.first)) d_cnt[x] += find_cnt(i.first, x);
	return d_cnt[x];
}
void find_core(int x, int up, int up_cnt) {
	bool core_check = true;

	if (up_cnt > len / 2) return;
	for(auto i:r[x])
		if (i.first != up && check_can(x, i.first)) {
			if (d_cnt[i.first] > len / 2) core_check = false;
			find_core(i.first, x, up_cnt + d_cnt[x] - d_cnt[i.first]);
		}
	if (core_check) core = x;
}
void Update(int x, int up, int tot_len, int cnt) {
	if (tot_len > m) return;

	if (d[m - tot_len].first == core) out = min2(out, cnt + d[m - tot_len].second);

	for (auto i : r[x])
		if (i.first != up && check_can(x, i.first)) Update(i.first, x, tot_len + i.second, cnt + 1);

}
void Push(int x, int up, int tot_len, int cnt) {
	if (tot_len > m) return;

	if (d[tot_len].first != core) d[tot_len] = { core,cnt };
	else if (d[tot_len].second > cnt) d[tot_len] = { core,cnt };
	
	for (auto i : r[x])
		if (i.first != up && check_can(x, i.first)) Push(i.first, x, tot_len + i.second, cnt + 1);

}
void f(int start) {
	len = 0, find_len(start);
	find_cnt(start, 0), find_core(start, 0, 0);

	d[0] = { core,0 };
	for (auto i : r[core])
		if (check_can(core, i.first)) {
			Update(i.first, core, i.second, 1);
			Push(i.first, core, i.second, 1);
		}

	int _core = core;
	for (auto i : r[_core])
		if (check_can(_core, i.first)) {
			prohibit[_core].insert(i.first);
			prohibit[i.first].insert(_core);
			f(i.first);
		}
}
int best_path(int _n, int _m, int in1[][2], int in2[]) {
	n = _n, m = _m;
	for (int i = 0; i < n - 1; i++) {
		int x = in1[i][0] + 1, y = in1[i][1] + 1;
		r[x].push_back({ y,in2[i] });
		r[y].push_back({ x,in2[i] });
	}

	f(1);
	return out == INF ? -1 : out;
}
# Verdict Execution time Memory Grader output
1 Correct 13 ms 14456 KB Output is correct
2 Correct 14 ms 14456 KB Output is correct
3 Correct 15 ms 14456 KB Output is correct
4 Correct 12 ms 14516 KB Output is correct
5 Correct 13 ms 14572 KB Output is correct
6 Correct 12 ms 14648 KB Output is correct
7 Correct 14 ms 14660 KB Output is correct
8 Correct 16 ms 14716 KB Output is correct
9 Correct 14 ms 14716 KB Output is correct
10 Correct 14 ms 14716 KB Output is correct
11 Correct 12 ms 14732 KB Output is correct
12 Correct 13 ms 14732 KB Output is correct
13 Correct 12 ms 14732 KB Output is correct
14 Correct 13 ms 14732 KB Output is correct
15 Correct 13 ms 14732 KB Output is correct
16 Correct 13 ms 14732 KB Output is correct
17 Correct 15 ms 14732 KB Output is correct
18 Correct 12 ms 14732 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 14456 KB Output is correct
2 Correct 14 ms 14456 KB Output is correct
3 Correct 15 ms 14456 KB Output is correct
4 Correct 12 ms 14516 KB Output is correct
5 Correct 13 ms 14572 KB Output is correct
6 Correct 12 ms 14648 KB Output is correct
7 Correct 14 ms 14660 KB Output is correct
8 Correct 16 ms 14716 KB Output is correct
9 Correct 14 ms 14716 KB Output is correct
10 Correct 14 ms 14716 KB Output is correct
11 Correct 12 ms 14732 KB Output is correct
12 Correct 13 ms 14732 KB Output is correct
13 Correct 12 ms 14732 KB Output is correct
14 Correct 13 ms 14732 KB Output is correct
15 Correct 13 ms 14732 KB Output is correct
16 Correct 13 ms 14732 KB Output is correct
17 Correct 15 ms 14732 KB Output is correct
18 Correct 12 ms 14732 KB Output is correct
19 Correct 16 ms 14732 KB Output is correct
20 Correct 13 ms 14732 KB Output is correct
21 Correct 14 ms 14844 KB Output is correct
22 Correct 18 ms 18224 KB Output is correct
23 Correct 19 ms 18224 KB Output is correct
24 Correct 24 ms 18940 KB Output is correct
25 Correct 19 ms 18940 KB Output is correct
26 Correct 17 ms 18940 KB Output is correct
27 Correct 13 ms 18940 KB Output is correct
28 Correct 16 ms 18940 KB Output is correct
29 Correct 19 ms 18940 KB Output is correct
30 Correct 17 ms 18940 KB Output is correct
31 Correct 18 ms 18940 KB Output is correct
32 Correct 18 ms 18940 KB Output is correct
33 Correct 20 ms 19704 KB Output is correct
34 Correct 19 ms 19704 KB Output is correct
35 Correct 22 ms 19708 KB Output is correct
36 Correct 26 ms 20220 KB Output is correct
37 Correct 18 ms 20220 KB Output is correct
38 Correct 17 ms 20220 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 14456 KB Output is correct
2 Correct 14 ms 14456 KB Output is correct
3 Correct 15 ms 14456 KB Output is correct
4 Correct 12 ms 14516 KB Output is correct
5 Correct 13 ms 14572 KB Output is correct
6 Correct 12 ms 14648 KB Output is correct
7 Correct 14 ms 14660 KB Output is correct
8 Correct 16 ms 14716 KB Output is correct
9 Correct 14 ms 14716 KB Output is correct
10 Correct 14 ms 14716 KB Output is correct
11 Correct 12 ms 14732 KB Output is correct
12 Correct 13 ms 14732 KB Output is correct
13 Correct 12 ms 14732 KB Output is correct
14 Correct 13 ms 14732 KB Output is correct
15 Correct 13 ms 14732 KB Output is correct
16 Correct 13 ms 14732 KB Output is correct
17 Correct 15 ms 14732 KB Output is correct
18 Correct 12 ms 14732 KB Output is correct
19 Correct 310 ms 30968 KB Output is correct
20 Correct 375 ms 30968 KB Output is correct
21 Correct 417 ms 31076 KB Output is correct
22 Correct 379 ms 31076 KB Output is correct
23 Correct 222 ms 31196 KB Output is correct
24 Correct 225 ms 31196 KB Output is correct
25 Correct 410 ms 34556 KB Output is correct
26 Correct 169 ms 38268 KB Output is correct
27 Correct 364 ms 47484 KB Output is correct
28 Correct 851 ms 61760 KB Output is correct
29 Correct 948 ms 61760 KB Output is correct
30 Correct 399 ms 61760 KB Output is correct
31 Correct 441 ms 61760 KB Output is correct
32 Correct 541 ms 61760 KB Output is correct
33 Correct 716 ms 61760 KB Output is correct
34 Correct 661 ms 61760 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 14456 KB Output is correct
2 Correct 14 ms 14456 KB Output is correct
3 Correct 15 ms 14456 KB Output is correct
4 Correct 12 ms 14516 KB Output is correct
5 Correct 13 ms 14572 KB Output is correct
6 Correct 12 ms 14648 KB Output is correct
7 Correct 14 ms 14660 KB Output is correct
8 Correct 16 ms 14716 KB Output is correct
9 Correct 14 ms 14716 KB Output is correct
10 Correct 14 ms 14716 KB Output is correct
11 Correct 12 ms 14732 KB Output is correct
12 Correct 13 ms 14732 KB Output is correct
13 Correct 12 ms 14732 KB Output is correct
14 Correct 13 ms 14732 KB Output is correct
15 Correct 13 ms 14732 KB Output is correct
16 Correct 13 ms 14732 KB Output is correct
17 Correct 15 ms 14732 KB Output is correct
18 Correct 12 ms 14732 KB Output is correct
19 Correct 16 ms 14732 KB Output is correct
20 Correct 13 ms 14732 KB Output is correct
21 Correct 14 ms 14844 KB Output is correct
22 Correct 18 ms 18224 KB Output is correct
23 Correct 19 ms 18224 KB Output is correct
24 Correct 24 ms 18940 KB Output is correct
25 Correct 19 ms 18940 KB Output is correct
26 Correct 17 ms 18940 KB Output is correct
27 Correct 13 ms 18940 KB Output is correct
28 Correct 16 ms 18940 KB Output is correct
29 Correct 19 ms 18940 KB Output is correct
30 Correct 17 ms 18940 KB Output is correct
31 Correct 18 ms 18940 KB Output is correct
32 Correct 18 ms 18940 KB Output is correct
33 Correct 20 ms 19704 KB Output is correct
34 Correct 19 ms 19704 KB Output is correct
35 Correct 22 ms 19708 KB Output is correct
36 Correct 26 ms 20220 KB Output is correct
37 Correct 18 ms 20220 KB Output is correct
38 Correct 17 ms 20220 KB Output is correct
39 Correct 310 ms 30968 KB Output is correct
40 Correct 375 ms 30968 KB Output is correct
41 Correct 417 ms 31076 KB Output is correct
42 Correct 379 ms 31076 KB Output is correct
43 Correct 222 ms 31196 KB Output is correct
44 Correct 225 ms 31196 KB Output is correct
45 Correct 410 ms 34556 KB Output is correct
46 Correct 169 ms 38268 KB Output is correct
47 Correct 364 ms 47484 KB Output is correct
48 Correct 851 ms 61760 KB Output is correct
49 Correct 948 ms 61760 KB Output is correct
50 Correct 399 ms 61760 KB Output is correct
51 Correct 441 ms 61760 KB Output is correct
52 Correct 541 ms 61760 KB Output is correct
53 Correct 716 ms 61760 KB Output is correct
54 Correct 661 ms 61760 KB Output is correct
55 Correct 29 ms 61760 KB Output is correct
56 Correct 34 ms 61760 KB Output is correct
57 Correct 154 ms 61760 KB Output is correct
58 Correct 125 ms 61760 KB Output is correct
59 Correct 204 ms 61760 KB Output is correct
60 Correct 1293 ms 65984 KB Output is correct
61 Correct 423 ms 65984 KB Output is correct
62 Correct 353 ms 65984 KB Output is correct
63 Correct 560 ms 65984 KB Output is correct
64 Correct 1147 ms 65984 KB Output is correct
65 Correct 599 ms 65984 KB Output is correct
66 Correct 1077 ms 65984 KB Output is correct
67 Correct 528 ms 65984 KB Output is correct
68 Correct 620 ms 65984 KB Output is correct
69 Correct 641 ms 65984 KB Output is correct
70 Correct 622 ms 65984 KB Output is correct