Submission #784687

# Submission time Handle Problem Language Result Execution time Memory
784687 2023-07-16T12:18:28 Z aVe Race (IOI11_race) C++14
100 / 100
323 ms 49724 KB
#include <bits/stdc++.h>
#include "race.h"
using namespace std;
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<long long, long long> pll;
typedef pair<int,int> pii;
typedef vector<long long> vl;
typedef vector<int> vi;
const int N = 1e6 + 5;
vector<pii> G[N];
int ans = 1e9, arr[N], tmp[N], sz[N], k, mx,n;
bool vis[N];
int get_sz(int node, int p = -1){
	sz[node] = 1;
	for(auto next : G[node]){
		if(next.first != p && !vis[next.first]){
			sz[node] += get_sz(next.first, node);
		}
	}
	return sz[node];
}
int get_centroid(int node, int size, int p = -1){
	for(auto next : G[node]){
		if(next.first == p || vis[next.first])	continue;
		if(sz[next.first] >= size)	return get_centroid(next.first, size, node);
	}
	return node;
}
void cnt(int node, int p, int yes, int sum, int level){
	if (sum > k) return;
    if (sum == k) ans = min(ans, level);
    if (yes == 1) tmp[sum] = min(tmp[sum], level);
    else if (yes) tmp[sum] = 1e9;
    else ans = min(ans, level + tmp[k - sum]);
    for (auto x:G[node]) 
		if (x.first != p && !vis[x.first]) 
			cnt(x.first, node, yes, sum + x.second, level + 1);
}
void decompose(int node = 0){
    get_sz(node);
    int c = get_centroid(node, sz[node] / 2);
    vis[c] = 1;
    mx = 0;
    for (auto x:G[c]) if (!vis[x.first]) cnt(x.first, c, 0, x.second, 1), cnt(x.first, c, 1, x.second, 1);
    for (auto x:G[c]) if (!vis[x.first]) cnt(x.first, c, 2, x.second, 1);
    for (auto x:G[c]) if (!vis[x.first]) decompose(x.first);
}
int best_path(int N, int K, int H[][2], int L[]){
	fill(tmp, tmp+1000000 + 5, 1e9);
	n= N, k = K;
	for(int i = 0; i < N-1; i++){
		G[H[i][1]].pb({H[i][0], L[i]});
		G[H[i][0]].pb({H[i][1], L[i]});
	}
	decompose();
	return (ans == 1e9) ? -1 : ans;
}
# Verdict Execution time Memory Grader output
1 Correct 12 ms 27732 KB Output is correct
2 Correct 15 ms 27664 KB Output is correct
3 Correct 13 ms 27656 KB Output is correct
4 Correct 12 ms 27636 KB Output is correct
5 Correct 13 ms 27732 KB Output is correct
6 Correct 13 ms 27732 KB Output is correct
7 Correct 12 ms 27740 KB Output is correct
8 Correct 13 ms 27732 KB Output is correct
9 Correct 13 ms 27728 KB Output is correct
10 Correct 13 ms 27732 KB Output is correct
11 Correct 13 ms 27744 KB Output is correct
12 Correct 15 ms 27740 KB Output is correct
13 Correct 13 ms 27644 KB Output is correct
14 Correct 13 ms 27744 KB Output is correct
15 Correct 13 ms 27720 KB Output is correct
16 Correct 12 ms 27732 KB Output is correct
17 Correct 13 ms 27644 KB Output is correct
18 Correct 13 ms 27732 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 27732 KB Output is correct
2 Correct 15 ms 27664 KB Output is correct
3 Correct 13 ms 27656 KB Output is correct
4 Correct 12 ms 27636 KB Output is correct
5 Correct 13 ms 27732 KB Output is correct
6 Correct 13 ms 27732 KB Output is correct
7 Correct 12 ms 27740 KB Output is correct
8 Correct 13 ms 27732 KB Output is correct
9 Correct 13 ms 27728 KB Output is correct
10 Correct 13 ms 27732 KB Output is correct
11 Correct 13 ms 27744 KB Output is correct
12 Correct 15 ms 27740 KB Output is correct
13 Correct 13 ms 27644 KB Output is correct
14 Correct 13 ms 27744 KB Output is correct
15 Correct 13 ms 27720 KB Output is correct
16 Correct 12 ms 27732 KB Output is correct
17 Correct 13 ms 27644 KB Output is correct
18 Correct 13 ms 27732 KB Output is correct
19 Correct 12 ms 27732 KB Output is correct
20 Correct 11 ms 27744 KB Output is correct
21 Correct 13 ms 27732 KB Output is correct
22 Correct 13 ms 27708 KB Output is correct
23 Correct 15 ms 27792 KB Output is correct
24 Correct 15 ms 27788 KB Output is correct
25 Correct 17 ms 27776 KB Output is correct
26 Correct 14 ms 27732 KB Output is correct
27 Correct 14 ms 27788 KB Output is correct
28 Correct 14 ms 27768 KB Output is correct
29 Correct 14 ms 27684 KB Output is correct
30 Correct 15 ms 27792 KB Output is correct
31 Correct 14 ms 27732 KB Output is correct
32 Correct 13 ms 27732 KB Output is correct
33 Correct 14 ms 27784 KB Output is correct
34 Correct 16 ms 27876 KB Output is correct
35 Correct 13 ms 27792 KB Output is correct
36 Correct 13 ms 27796 KB Output is correct
37 Correct 13 ms 27776 KB Output is correct
38 Correct 12 ms 27748 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 27732 KB Output is correct
2 Correct 15 ms 27664 KB Output is correct
3 Correct 13 ms 27656 KB Output is correct
4 Correct 12 ms 27636 KB Output is correct
5 Correct 13 ms 27732 KB Output is correct
6 Correct 13 ms 27732 KB Output is correct
7 Correct 12 ms 27740 KB Output is correct
8 Correct 13 ms 27732 KB Output is correct
9 Correct 13 ms 27728 KB Output is correct
10 Correct 13 ms 27732 KB Output is correct
11 Correct 13 ms 27744 KB Output is correct
12 Correct 15 ms 27740 KB Output is correct
13 Correct 13 ms 27644 KB Output is correct
14 Correct 13 ms 27744 KB Output is correct
15 Correct 13 ms 27720 KB Output is correct
16 Correct 12 ms 27732 KB Output is correct
17 Correct 13 ms 27644 KB Output is correct
18 Correct 13 ms 27732 KB Output is correct
19 Correct 113 ms 33036 KB Output is correct
20 Correct 102 ms 32972 KB Output is correct
21 Correct 111 ms 33060 KB Output is correct
22 Correct 109 ms 33112 KB Output is correct
23 Correct 63 ms 33288 KB Output is correct
24 Correct 55 ms 33164 KB Output is correct
25 Correct 112 ms 35804 KB Output is correct
26 Correct 105 ms 38672 KB Output is correct
27 Correct 130 ms 38548 KB Output is correct
28 Correct 172 ms 49724 KB Output is correct
29 Correct 176 ms 48852 KB Output is correct
30 Correct 124 ms 38596 KB Output is correct
31 Correct 135 ms 38564 KB Output is correct
32 Correct 140 ms 38600 KB Output is correct
33 Correct 162 ms 37344 KB Output is correct
34 Correct 128 ms 37408 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 27732 KB Output is correct
2 Correct 15 ms 27664 KB Output is correct
3 Correct 13 ms 27656 KB Output is correct
4 Correct 12 ms 27636 KB Output is correct
5 Correct 13 ms 27732 KB Output is correct
6 Correct 13 ms 27732 KB Output is correct
7 Correct 12 ms 27740 KB Output is correct
8 Correct 13 ms 27732 KB Output is correct
9 Correct 13 ms 27728 KB Output is correct
10 Correct 13 ms 27732 KB Output is correct
11 Correct 13 ms 27744 KB Output is correct
12 Correct 15 ms 27740 KB Output is correct
13 Correct 13 ms 27644 KB Output is correct
14 Correct 13 ms 27744 KB Output is correct
15 Correct 13 ms 27720 KB Output is correct
16 Correct 12 ms 27732 KB Output is correct
17 Correct 13 ms 27644 KB Output is correct
18 Correct 13 ms 27732 KB Output is correct
19 Correct 12 ms 27732 KB Output is correct
20 Correct 11 ms 27744 KB Output is correct
21 Correct 13 ms 27732 KB Output is correct
22 Correct 13 ms 27708 KB Output is correct
23 Correct 15 ms 27792 KB Output is correct
24 Correct 15 ms 27788 KB Output is correct
25 Correct 17 ms 27776 KB Output is correct
26 Correct 14 ms 27732 KB Output is correct
27 Correct 14 ms 27788 KB Output is correct
28 Correct 14 ms 27768 KB Output is correct
29 Correct 14 ms 27684 KB Output is correct
30 Correct 15 ms 27792 KB Output is correct
31 Correct 14 ms 27732 KB Output is correct
32 Correct 13 ms 27732 KB Output is correct
33 Correct 14 ms 27784 KB Output is correct
34 Correct 16 ms 27876 KB Output is correct
35 Correct 13 ms 27792 KB Output is correct
36 Correct 13 ms 27796 KB Output is correct
37 Correct 13 ms 27776 KB Output is correct
38 Correct 12 ms 27748 KB Output is correct
39 Correct 113 ms 33036 KB Output is correct
40 Correct 102 ms 32972 KB Output is correct
41 Correct 111 ms 33060 KB Output is correct
42 Correct 109 ms 33112 KB Output is correct
43 Correct 63 ms 33288 KB Output is correct
44 Correct 55 ms 33164 KB Output is correct
45 Correct 112 ms 35804 KB Output is correct
46 Correct 105 ms 38672 KB Output is correct
47 Correct 130 ms 38548 KB Output is correct
48 Correct 172 ms 49724 KB Output is correct
49 Correct 176 ms 48852 KB Output is correct
50 Correct 124 ms 38596 KB Output is correct
51 Correct 135 ms 38564 KB Output is correct
52 Correct 140 ms 38600 KB Output is correct
53 Correct 162 ms 37344 KB Output is correct
54 Correct 128 ms 37408 KB Output is correct
55 Correct 20 ms 28208 KB Output is correct
56 Correct 24 ms 28188 KB Output is correct
57 Correct 70 ms 33260 KB Output is correct
58 Correct 39 ms 33244 KB Output is correct
59 Correct 97 ms 38776 KB Output is correct
60 Correct 323 ms 49100 KB Output is correct
61 Correct 134 ms 38580 KB Output is correct
62 Correct 158 ms 38604 KB Output is correct
63 Correct 204 ms 38592 KB Output is correct
64 Correct 307 ms 38280 KB Output is correct
65 Correct 144 ms 38512 KB Output is correct
66 Correct 277 ms 46752 KB Output is correct
67 Correct 85 ms 38780 KB Output is correct
68 Correct 205 ms 38744 KB Output is correct
69 Correct 188 ms 38816 KB Output is correct
70 Correct 181 ms 38332 KB Output is correct