Submission #896138

# Submission time Handle Problem Language Result Execution time Memory
896138 2023-12-31T22:02:04 Z starchan Race (IOI11_race) C++17
100 / 100
243 ms 40860 KB
#include "race.h"
#include<bits/stdc++.h>
using namespace std;
#define in pair<int, int>
#define f first
#define s second
#define pb push_back
#define pob pop_back
#define INF (int)1e9
#define MX (int)2e5+5
#define LMX (int)1e6+5
#define fast() ios_base::sync_with_stdio(false); cin.tie(NULL)
int n, k;
vector<in> adj[MX];
int sz[MX];
bool cut[MX];

void calc_subtree(int u, int p)
{
	sz[u] = 1;
	for(auto [v, w]: adj[u])
	{
		if(v==p)
			continue;
		if(cut[v])
			continue;
		calc_subtree(v, u);
		sz[u]+=sz[v];
	}
	return;
}

int centroid(int root, int u, int p)
{
	for(auto [v, w]: adj[u])
	{
		if(cut[v])
			continue;
		if(v==p)
			continue;
		if(2*sz[v] > sz[root])
			return centroid(root, v, u);
	}
	return u;
}
vector<int> curr;
vector<int> on;
vector<int> best(LMX, INF);
int ans = INF;
void ritul(int u, int p, int lvl, int dist)
{
	if(dist > k)
		return;
	ans = min(ans, lvl+best[k-dist]);
	for(auto [v, w]: adj[u])
	{
		if(v==p)
			continue;
		if(cut[v])
			continue;
		ritul(v, u, lvl+1, dist+w);
	}
	return;
}

void ritul2(int u, int p, int lvl, int dist)
{
	if(dist > k)
		return;
	curr.pb(dist);
	best[dist] = min(best[dist], lvl);
	for(auto [v, w]: adj[u])
	{
		if(v==p)
			continue;
		if(cut[v])
			continue;
		ritul2(v, u, lvl+1, dist+w);
	}
	return;
}

void centroid_decomp(int u)
{
	calc_subtree(u, -1);
	int root = centroid(u, u, -1);
	cut[root] = 1;
	curr.clear();
	for(auto [v, w]: adj[root])
	{
		if(cut[v])
			continue;
		ritul(v, root, 1, w);
		ritul2(v, root, 1, w);
	}
	for(int t: curr)
		best[t] = INF;
	for(auto [v, w]: adj[root])
	{
		if(cut[v])
			continue;
		centroid_decomp(v);
	}
	return;
}

int best_path(int N, int K, int h[][2], int L[])
{
	n = N;
	k = K;
	for(int i = 0; i < n-1; i++)
	{
		int u = h[i][0];
		int v = h[i][1];
		u++;
		v++;
		int l = L[i];
		adj[u].pb({v, l});
		adj[v].pb({u, l});
	}
	best[0] = 0;
	centroid_decomp(1);
	if(ans == INF)
		ans = -1;
	return ans;
}
/*
signed main()
{
	int V, KK;
	cin >> V >> KK;
	int h[V-1][2];	
	int L[V-1];
	for(int i = 0; i < V-1; i++)
		cin >> h[i][0] >> h[i][1] >> L[i];
	int ok = best_path(V, KK, h, L);
	cout << ok << endl; 
	return 0;
}
*/
# Verdict Execution time Memory Grader output
1 Correct 3 ms 13660 KB Output is correct
2 Correct 3 ms 13516 KB Output is correct
3 Correct 3 ms 13660 KB Output is correct
4 Correct 3 ms 13660 KB Output is correct
5 Correct 3 ms 13660 KB Output is correct
6 Correct 3 ms 13680 KB Output is correct
7 Correct 4 ms 13660 KB Output is correct
8 Correct 4 ms 13496 KB Output is correct
9 Correct 3 ms 13656 KB Output is correct
10 Correct 4 ms 13656 KB Output is correct
11 Correct 3 ms 13656 KB Output is correct
12 Correct 3 ms 13660 KB Output is correct
13 Correct 3 ms 13660 KB Output is correct
14 Correct 4 ms 13660 KB Output is correct
15 Correct 4 ms 13680 KB Output is correct
16 Correct 3 ms 13660 KB Output is correct
17 Correct 3 ms 13660 KB Output is correct
18 Correct 3 ms 13660 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 13660 KB Output is correct
2 Correct 3 ms 13516 KB Output is correct
3 Correct 3 ms 13660 KB Output is correct
4 Correct 3 ms 13660 KB Output is correct
5 Correct 3 ms 13660 KB Output is correct
6 Correct 3 ms 13680 KB Output is correct
7 Correct 4 ms 13660 KB Output is correct
8 Correct 4 ms 13496 KB Output is correct
9 Correct 3 ms 13656 KB Output is correct
10 Correct 4 ms 13656 KB Output is correct
11 Correct 3 ms 13656 KB Output is correct
12 Correct 3 ms 13660 KB Output is correct
13 Correct 3 ms 13660 KB Output is correct
14 Correct 4 ms 13660 KB Output is correct
15 Correct 4 ms 13680 KB Output is correct
16 Correct 3 ms 13660 KB Output is correct
17 Correct 3 ms 13660 KB Output is correct
18 Correct 3 ms 13660 KB Output is correct
19 Correct 4 ms 13660 KB Output is correct
20 Correct 3 ms 13660 KB Output is correct
21 Correct 3 ms 13660 KB Output is correct
22 Correct 4 ms 13660 KB Output is correct
23 Correct 4 ms 13660 KB Output is correct
24 Correct 4 ms 13660 KB Output is correct
25 Correct 4 ms 13660 KB Output is correct
26 Correct 4 ms 13660 KB Output is correct
27 Correct 4 ms 13656 KB Output is correct
28 Correct 4 ms 13660 KB Output is correct
29 Correct 4 ms 13912 KB Output is correct
30 Correct 4 ms 13660 KB Output is correct
31 Correct 4 ms 13660 KB Output is correct
32 Correct 4 ms 13660 KB Output is correct
33 Correct 4 ms 13656 KB Output is correct
34 Correct 4 ms 13660 KB Output is correct
35 Correct 4 ms 13660 KB Output is correct
36 Correct 4 ms 13660 KB Output is correct
37 Correct 4 ms 13692 KB Output is correct
38 Correct 4 ms 13660 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 13660 KB Output is correct
2 Correct 3 ms 13516 KB Output is correct
3 Correct 3 ms 13660 KB Output is correct
4 Correct 3 ms 13660 KB Output is correct
5 Correct 3 ms 13660 KB Output is correct
6 Correct 3 ms 13680 KB Output is correct
7 Correct 4 ms 13660 KB Output is correct
8 Correct 4 ms 13496 KB Output is correct
9 Correct 3 ms 13656 KB Output is correct
10 Correct 4 ms 13656 KB Output is correct
11 Correct 3 ms 13656 KB Output is correct
12 Correct 3 ms 13660 KB Output is correct
13 Correct 3 ms 13660 KB Output is correct
14 Correct 4 ms 13660 KB Output is correct
15 Correct 4 ms 13680 KB Output is correct
16 Correct 3 ms 13660 KB Output is correct
17 Correct 3 ms 13660 KB Output is correct
18 Correct 3 ms 13660 KB Output is correct
19 Correct 79 ms 20592 KB Output is correct
20 Correct 75 ms 20812 KB Output is correct
21 Correct 80 ms 20892 KB Output is correct
22 Correct 71 ms 21196 KB Output is correct
23 Correct 47 ms 20816 KB Output is correct
24 Correct 38 ms 20560 KB Output is correct
25 Correct 76 ms 24180 KB Output is correct
26 Correct 68 ms 28480 KB Output is correct
27 Correct 102 ms 25168 KB Output is correct
28 Correct 158 ms 40820 KB Output is correct
29 Correct 190 ms 39692 KB Output is correct
30 Correct 98 ms 26192 KB Output is correct
31 Correct 104 ms 26356 KB Output is correct
32 Correct 108 ms 26452 KB Output is correct
33 Correct 119 ms 25224 KB Output is correct
34 Correct 110 ms 25980 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 13660 KB Output is correct
2 Correct 3 ms 13516 KB Output is correct
3 Correct 3 ms 13660 KB Output is correct
4 Correct 3 ms 13660 KB Output is correct
5 Correct 3 ms 13660 KB Output is correct
6 Correct 3 ms 13680 KB Output is correct
7 Correct 4 ms 13660 KB Output is correct
8 Correct 4 ms 13496 KB Output is correct
9 Correct 3 ms 13656 KB Output is correct
10 Correct 4 ms 13656 KB Output is correct
11 Correct 3 ms 13656 KB Output is correct
12 Correct 3 ms 13660 KB Output is correct
13 Correct 3 ms 13660 KB Output is correct
14 Correct 4 ms 13660 KB Output is correct
15 Correct 4 ms 13680 KB Output is correct
16 Correct 3 ms 13660 KB Output is correct
17 Correct 3 ms 13660 KB Output is correct
18 Correct 3 ms 13660 KB Output is correct
19 Correct 4 ms 13660 KB Output is correct
20 Correct 3 ms 13660 KB Output is correct
21 Correct 3 ms 13660 KB Output is correct
22 Correct 4 ms 13660 KB Output is correct
23 Correct 4 ms 13660 KB Output is correct
24 Correct 4 ms 13660 KB Output is correct
25 Correct 4 ms 13660 KB Output is correct
26 Correct 4 ms 13660 KB Output is correct
27 Correct 4 ms 13656 KB Output is correct
28 Correct 4 ms 13660 KB Output is correct
29 Correct 4 ms 13912 KB Output is correct
30 Correct 4 ms 13660 KB Output is correct
31 Correct 4 ms 13660 KB Output is correct
32 Correct 4 ms 13660 KB Output is correct
33 Correct 4 ms 13656 KB Output is correct
34 Correct 4 ms 13660 KB Output is correct
35 Correct 4 ms 13660 KB Output is correct
36 Correct 4 ms 13660 KB Output is correct
37 Correct 4 ms 13692 KB Output is correct
38 Correct 4 ms 13660 KB Output is correct
39 Correct 79 ms 20592 KB Output is correct
40 Correct 75 ms 20812 KB Output is correct
41 Correct 80 ms 20892 KB Output is correct
42 Correct 71 ms 21196 KB Output is correct
43 Correct 47 ms 20816 KB Output is correct
44 Correct 38 ms 20560 KB Output is correct
45 Correct 76 ms 24180 KB Output is correct
46 Correct 68 ms 28480 KB Output is correct
47 Correct 102 ms 25168 KB Output is correct
48 Correct 158 ms 40820 KB Output is correct
49 Correct 190 ms 39692 KB Output is correct
50 Correct 98 ms 26192 KB Output is correct
51 Correct 104 ms 26356 KB Output is correct
52 Correct 108 ms 26452 KB Output is correct
53 Correct 119 ms 25224 KB Output is correct
54 Correct 110 ms 25980 KB Output is correct
55 Correct 9 ms 14172 KB Output is correct
56 Correct 9 ms 14168 KB Output is correct
57 Correct 54 ms 21664 KB Output is correct
58 Correct 28 ms 21688 KB Output is correct
59 Correct 68 ms 28820 KB Output is correct
60 Correct 242 ms 40860 KB Output is correct
61 Correct 109 ms 26964 KB Output is correct
62 Correct 118 ms 27600 KB Output is correct
63 Correct 144 ms 27940 KB Output is correct
64 Correct 230 ms 27596 KB Output is correct
65 Correct 109 ms 27172 KB Output is correct
66 Correct 243 ms 37328 KB Output is correct
67 Correct 68 ms 28868 KB Output is correct
68 Correct 134 ms 27856 KB Output is correct
69 Correct 135 ms 27904 KB Output is correct
70 Correct 127 ms 27340 KB Output is correct