답안 #1112940

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1112940 2024-11-15T09:44:23 Z akzytr 경주 (Race) (IOI11_race) C++17
43 / 100
3000 ms 106484 KB
#include "race.h"
#include <bits/stdc++.h>
#define ve vector
#define pb push_back
#define ar array
#define ll long long
using namespace std;

const int MAXN = 3e5;
set<int> adj[MAXN];
map<ar<int, 2>, int> w;

int K;
int ANS = 1e9;

int sub[MAXN];
int processed[MAXN];

void find_size(int x, int p) {
	sub[x] = 1;
	for(int i : adj[x]) {
		if(i != p && !processed[i]) {
			find_size(i, x);
			sub[x] += sub[i];
		}
	}
}
int find_centroid(int x, int p, int n) {
	for(int i : adj[x]) {
		if(sub[i] > n / 2 && i != p) {
			return find_centroid(i, x, n);
		}
	}
	return x;
}

void dfs(int x, int p, map<int, int> &vis, map<int, int> &mi_edge, int we, int num_edge, bool upd) {
	if(upd) {
		if(vis[we]) {
			mi_edge[we] = min(mi_edge[we], num_edge);
		} else {
			vis[we] = 1;
			mi_edge[we] = num_edge;
		}
	} else {
		if(vis[K - we]) {
			ANS = min(ANS, num_edge + mi_edge[K - we]);
		}
	}

	for(int i : adj[x]) {
		if(i != p && we + w[{i, x}] <= K && !processed[i]) {
			dfs(i, x, vis, mi_edge, we + w[{i, x}], num_edge + 1, upd);
		}
	}
}
void process_centroid(int x) {
	map<int, int> vis;
	map<int, int> mi_edge;
	mi_edge[0] = 0;
	vis[0] = 1;

	for(int i : adj[x]) {
		dfs(i, x, vis, mi_edge, w[{i, x}], 1, false);
		dfs(i, x, vis, mi_edge, w[{i, x}], 1, true);
	}
	processed[x] = 1;
}

void decompo(int x) {
	find_size(x, -1);
	int centroid = find_centroid(x, -1, sub[x]);
	process_centroid(centroid);

	for(int i : adj[centroid]) {
		adj[i].erase(centroid);
		decompo(i);
	}
}

int best_path(int N, int Ked, int H[][2], int L[]) {
	fill(processed, processed + MAXN, 0);
	for(int i = 0; i < N - 1; i++) {
		int a, b;
		a = H[i][0];
		b = H[i][1];

		adj[a].insert(b);
		adj[b].insert(a);
		w[{a, b}] = L[i];
		w[{b, a}] = L[i];
	}
	K = Ked;
	decompo(0);
	if(ANS != 1e9) {
		return ANS;
	}
	return -1;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 20560 KB Output is correct
2 Correct 10 ms 15864 KB Output is correct
3 Correct 12 ms 15732 KB Output is correct
4 Correct 14 ms 16720 KB Output is correct
5 Correct 11 ms 16720 KB Output is correct
6 Correct 11 ms 16720 KB Output is correct
7 Correct 11 ms 15696 KB Output is correct
8 Correct 13 ms 15508 KB Output is correct
9 Correct 11 ms 15696 KB Output is correct
10 Correct 11 ms 15756 KB Output is correct
11 Correct 11 ms 15696 KB Output is correct
12 Correct 11 ms 15564 KB Output is correct
13 Correct 11 ms 15696 KB Output is correct
14 Correct 11 ms 15864 KB Output is correct
15 Correct 11 ms 15696 KB Output is correct
16 Correct 11 ms 15696 KB Output is correct
17 Correct 12 ms 15588 KB Output is correct
18 Correct 5 ms 20560 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 20560 KB Output is correct
2 Correct 10 ms 15864 KB Output is correct
3 Correct 12 ms 15732 KB Output is correct
4 Correct 14 ms 16720 KB Output is correct
5 Correct 11 ms 16720 KB Output is correct
6 Correct 11 ms 16720 KB Output is correct
7 Correct 11 ms 15696 KB Output is correct
8 Correct 13 ms 15508 KB Output is correct
9 Correct 11 ms 15696 KB Output is correct
10 Correct 11 ms 15756 KB Output is correct
11 Correct 11 ms 15696 KB Output is correct
12 Correct 11 ms 15564 KB Output is correct
13 Correct 11 ms 15696 KB Output is correct
14 Correct 11 ms 15864 KB Output is correct
15 Correct 11 ms 15696 KB Output is correct
16 Correct 11 ms 15696 KB Output is correct
17 Correct 12 ms 15588 KB Output is correct
18 Correct 5 ms 20560 KB Output is correct
19 Correct 5 ms 20432 KB Output is correct
20 Correct 6 ms 20560 KB Output is correct
21 Correct 7 ms 18768 KB Output is correct
22 Correct 6 ms 17124 KB Output is correct
23 Correct 6 ms 18512 KB Output is correct
24 Correct 6 ms 20560 KB Output is correct
25 Correct 10 ms 18768 KB Output is correct
26 Correct 7 ms 20560 KB Output is correct
27 Correct 12 ms 15828 KB Output is correct
28 Correct 12 ms 16976 KB Output is correct
29 Correct 9 ms 17232 KB Output is correct
30 Correct 15 ms 19736 KB Output is correct
31 Correct 15 ms 17112 KB Output is correct
32 Correct 8 ms 17232 KB Output is correct
33 Correct 16 ms 15984 KB Output is correct
34 Correct 14 ms 15952 KB Output is correct
35 Correct 11 ms 16976 KB Output is correct
36 Correct 12 ms 17144 KB Output is correct
37 Correct 12 ms 17404 KB Output is correct
38 Correct 14 ms 17232 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 20560 KB Output is correct
2 Correct 10 ms 15864 KB Output is correct
3 Correct 12 ms 15732 KB Output is correct
4 Correct 14 ms 16720 KB Output is correct
5 Correct 11 ms 16720 KB Output is correct
6 Correct 11 ms 16720 KB Output is correct
7 Correct 11 ms 15696 KB Output is correct
8 Correct 13 ms 15508 KB Output is correct
9 Correct 11 ms 15696 KB Output is correct
10 Correct 11 ms 15756 KB Output is correct
11 Correct 11 ms 15696 KB Output is correct
12 Correct 11 ms 15564 KB Output is correct
13 Correct 11 ms 15696 KB Output is correct
14 Correct 11 ms 15864 KB Output is correct
15 Correct 11 ms 15696 KB Output is correct
16 Correct 11 ms 15696 KB Output is correct
17 Correct 12 ms 15588 KB Output is correct
18 Correct 5 ms 20560 KB Output is correct
19 Correct 873 ms 41328 KB Output is correct
20 Correct 809 ms 39752 KB Output is correct
21 Correct 1038 ms 40432 KB Output is correct
22 Correct 948 ms 40520 KB Output is correct
23 Correct 318 ms 41404 KB Output is correct
24 Correct 373 ms 45152 KB Output is correct
25 Correct 953 ms 45312 KB Output is correct
26 Correct 699 ms 48972 KB Output is correct
27 Correct 646 ms 68520 KB Output is correct
28 Correct 804 ms 81100 KB Output is correct
29 Correct 865 ms 80168 KB Output is correct
30 Correct 677 ms 65728 KB Output is correct
31 Correct 635 ms 65344 KB Output is correct
32 Correct 921 ms 65400 KB Output is correct
33 Correct 1511 ms 65564 KB Output is correct
34 Correct 717 ms 66692 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 20560 KB Output is correct
2 Correct 10 ms 15864 KB Output is correct
3 Correct 12 ms 15732 KB Output is correct
4 Correct 14 ms 16720 KB Output is correct
5 Correct 11 ms 16720 KB Output is correct
6 Correct 11 ms 16720 KB Output is correct
7 Correct 11 ms 15696 KB Output is correct
8 Correct 13 ms 15508 KB Output is correct
9 Correct 11 ms 15696 KB Output is correct
10 Correct 11 ms 15756 KB Output is correct
11 Correct 11 ms 15696 KB Output is correct
12 Correct 11 ms 15564 KB Output is correct
13 Correct 11 ms 15696 KB Output is correct
14 Correct 11 ms 15864 KB Output is correct
15 Correct 11 ms 15696 KB Output is correct
16 Correct 11 ms 15696 KB Output is correct
17 Correct 12 ms 15588 KB Output is correct
18 Correct 5 ms 20560 KB Output is correct
19 Correct 5 ms 20432 KB Output is correct
20 Correct 6 ms 20560 KB Output is correct
21 Correct 7 ms 18768 KB Output is correct
22 Correct 6 ms 17124 KB Output is correct
23 Correct 6 ms 18512 KB Output is correct
24 Correct 6 ms 20560 KB Output is correct
25 Correct 10 ms 18768 KB Output is correct
26 Correct 7 ms 20560 KB Output is correct
27 Correct 12 ms 15828 KB Output is correct
28 Correct 12 ms 16976 KB Output is correct
29 Correct 9 ms 17232 KB Output is correct
30 Correct 15 ms 19736 KB Output is correct
31 Correct 15 ms 17112 KB Output is correct
32 Correct 8 ms 17232 KB Output is correct
33 Correct 16 ms 15984 KB Output is correct
34 Correct 14 ms 15952 KB Output is correct
35 Correct 11 ms 16976 KB Output is correct
36 Correct 12 ms 17144 KB Output is correct
37 Correct 12 ms 17404 KB Output is correct
38 Correct 14 ms 17232 KB Output is correct
39 Correct 873 ms 41328 KB Output is correct
40 Correct 809 ms 39752 KB Output is correct
41 Correct 1038 ms 40432 KB Output is correct
42 Correct 948 ms 40520 KB Output is correct
43 Correct 318 ms 41404 KB Output is correct
44 Correct 373 ms 45152 KB Output is correct
45 Correct 953 ms 45312 KB Output is correct
46 Correct 699 ms 48972 KB Output is correct
47 Correct 646 ms 68520 KB Output is correct
48 Correct 804 ms 81100 KB Output is correct
49 Correct 865 ms 80168 KB Output is correct
50 Correct 677 ms 65728 KB Output is correct
51 Correct 635 ms 65344 KB Output is correct
52 Correct 921 ms 65400 KB Output is correct
53 Correct 1511 ms 65564 KB Output is correct
54 Correct 717 ms 66692 KB Output is correct
55 Correct 72 ms 19536 KB Output is correct
56 Correct 61 ms 18000 KB Output is correct
57 Correct 723 ms 40548 KB Output is correct
58 Correct 147 ms 40044 KB Output is correct
59 Correct 1162 ms 58448 KB Output is correct
60 Execution timed out 3065 ms 106484 KB Time limit exceeded
61 Halted 0 ms 0 KB -