Submission #922237

# Submission time Handle Problem Language Result Execution time Memory
922237 2024-02-05T09:33:52 Z Nurislam Race (IOI11_race) C++17
100 / 100
777 ms 38540 KB
#include "race.h"
//~ #include "grader.cpp"
#include <bits/stdc++.h>

using namespace std;

#define pb push_back
#define ff first
#define ss second

typedef vector<int> vi;
typedef vector<double> vd;
typedef pair<int,int> pii;
typedef vector<pii> vii;
typedef vector<vi> vv;
const int inf = 1e9, mxN = 2e5+2;

vii g[mxN];
int us[mxN];
int m, ctr, ans = inf;
int k;
map<int,int> mp;
int dfs_sz(int v, int pr){
	if(us[v])return 0;
	int s = 1;
	for(auto [to, cst]:g[v]){
		if(to == pr)continue;
		s += dfs_sz(to, v);
	}
	return s;
}
int dfs_ctr(int v, int pr){
	if(us[v])return 0;
	int s = 1;
	bool ok = 1;
	for(auto [to, cst]:g[v]){
		if(to == pr)continue;
		int sto = dfs_ctr(to, v);
		if(sto > m/2)ok = 0;
		s += sto;
	}
	if(s < m/2)ok = 0;
	if(ok)ctr = v;
	return s;
}
void dfs(int v, int pr, int dep, int sum, bool ok){
	if(sum > k)return;
    if (!ok){
        if ( sum == k ) ans = min(ans, dep);
        else ans = min(ans, !mp.count(k-sum) ? inf : mp[k-sum]+dep);
    }else{
        if ( !mp.count(sum) ) mp[sum] = dep;
        else mp[sum] = min(mp[sum], dep);
    }
    for(auto [to, w]:g[v]){
        if (us[to] || to == pr)continue;
        dfs(to, v, dep+1, sum+w, ok);
    }
}
void fun(int v){
	m = dfs_sz(v, -1);
	m = dfs_ctr(v, -1);
	us[ctr] = 1;
	mp.clear();
	for(auto [to, cst]:g[ctr]){
		if(us[to])continue;
		dfs(to, ctr, 1, cst, 0);
		dfs(to, ctr, 1, cst, 1);
	}
	for(auto [to, cst]:g[ctr]){
		if(us[to])continue;
		fun(to);
	}
}
int best_path(int n, int K, int h[][2], int l[])
{
	for(int i = 0; i < n-1; i++){
		g[h[i][0]].pb({h[i][1], l[i]});
		g[h[i][1]].pb({h[i][0], l[i]});
	}
	k = K;
	fun(0);
	return (ans == inf?-1:ans);
}







# Verdict Execution time Memory Grader output
1 Correct 2 ms 9560 KB Output is correct
2 Correct 2 ms 9564 KB Output is correct
3 Correct 2 ms 9564 KB Output is correct
4 Correct 2 ms 9564 KB Output is correct
5 Correct 2 ms 9564 KB Output is correct
6 Correct 2 ms 9564 KB Output is correct
7 Correct 2 ms 9564 KB Output is correct
8 Correct 2 ms 9564 KB Output is correct
9 Correct 2 ms 9564 KB Output is correct
10 Correct 2 ms 9564 KB Output is correct
11 Correct 2 ms 9564 KB Output is correct
12 Correct 2 ms 9560 KB Output is correct
13 Correct 2 ms 9560 KB Output is correct
14 Correct 3 ms 9564 KB Output is correct
15 Correct 2 ms 9564 KB Output is correct
16 Correct 2 ms 9564 KB Output is correct
17 Correct 2 ms 9564 KB Output is correct
18 Correct 3 ms 9564 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 9560 KB Output is correct
2 Correct 2 ms 9564 KB Output is correct
3 Correct 2 ms 9564 KB Output is correct
4 Correct 2 ms 9564 KB Output is correct
5 Correct 2 ms 9564 KB Output is correct
6 Correct 2 ms 9564 KB Output is correct
7 Correct 2 ms 9564 KB Output is correct
8 Correct 2 ms 9564 KB Output is correct
9 Correct 2 ms 9564 KB Output is correct
10 Correct 2 ms 9564 KB Output is correct
11 Correct 2 ms 9564 KB Output is correct
12 Correct 2 ms 9560 KB Output is correct
13 Correct 2 ms 9560 KB Output is correct
14 Correct 3 ms 9564 KB Output is correct
15 Correct 2 ms 9564 KB Output is correct
16 Correct 2 ms 9564 KB Output is correct
17 Correct 2 ms 9564 KB Output is correct
18 Correct 3 ms 9564 KB Output is correct
19 Correct 2 ms 9560 KB Output is correct
20 Correct 3 ms 9564 KB Output is correct
21 Correct 3 ms 9560 KB Output is correct
22 Correct 3 ms 9564 KB Output is correct
23 Correct 3 ms 9564 KB Output is correct
24 Correct 3 ms 9560 KB Output is correct
25 Correct 4 ms 9564 KB Output is correct
26 Correct 3 ms 9564 KB Output is correct
27 Correct 2 ms 9560 KB Output is correct
28 Correct 4 ms 9564 KB Output is correct
29 Correct 3 ms 9564 KB Output is correct
30 Correct 3 ms 9564 KB Output is correct
31 Correct 4 ms 9816 KB Output is correct
32 Correct 3 ms 9560 KB Output is correct
33 Correct 3 ms 9564 KB Output is correct
34 Correct 3 ms 9612 KB Output is correct
35 Correct 3 ms 9564 KB Output is correct
36 Correct 3 ms 9564 KB Output is correct
37 Correct 3 ms 9564 KB Output is correct
38 Correct 3 ms 9564 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 9560 KB Output is correct
2 Correct 2 ms 9564 KB Output is correct
3 Correct 2 ms 9564 KB Output is correct
4 Correct 2 ms 9564 KB Output is correct
5 Correct 2 ms 9564 KB Output is correct
6 Correct 2 ms 9564 KB Output is correct
7 Correct 2 ms 9564 KB Output is correct
8 Correct 2 ms 9564 KB Output is correct
9 Correct 2 ms 9564 KB Output is correct
10 Correct 2 ms 9564 KB Output is correct
11 Correct 2 ms 9564 KB Output is correct
12 Correct 2 ms 9560 KB Output is correct
13 Correct 2 ms 9560 KB Output is correct
14 Correct 3 ms 9564 KB Output is correct
15 Correct 2 ms 9564 KB Output is correct
16 Correct 2 ms 9564 KB Output is correct
17 Correct 2 ms 9564 KB Output is correct
18 Correct 3 ms 9564 KB Output is correct
19 Correct 141 ms 15196 KB Output is correct
20 Correct 143 ms 15336 KB Output is correct
21 Correct 170 ms 15452 KB Output is correct
22 Correct 151 ms 15620 KB Output is correct
23 Correct 61 ms 15440 KB Output is correct
24 Correct 56 ms 15816 KB Output is correct
25 Correct 130 ms 18256 KB Output is correct
26 Correct 94 ms 21328 KB Output is correct
27 Correct 141 ms 19280 KB Output is correct
28 Correct 225 ms 30484 KB Output is correct
29 Correct 190 ms 29424 KB Output is correct
30 Correct 141 ms 19324 KB Output is correct
31 Correct 141 ms 19284 KB Output is correct
32 Correct 170 ms 19192 KB Output is correct
33 Correct 196 ms 18000 KB Output is correct
34 Correct 124 ms 18156 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 9560 KB Output is correct
2 Correct 2 ms 9564 KB Output is correct
3 Correct 2 ms 9564 KB Output is correct
4 Correct 2 ms 9564 KB Output is correct
5 Correct 2 ms 9564 KB Output is correct
6 Correct 2 ms 9564 KB Output is correct
7 Correct 2 ms 9564 KB Output is correct
8 Correct 2 ms 9564 KB Output is correct
9 Correct 2 ms 9564 KB Output is correct
10 Correct 2 ms 9564 KB Output is correct
11 Correct 2 ms 9564 KB Output is correct
12 Correct 2 ms 9560 KB Output is correct
13 Correct 2 ms 9560 KB Output is correct
14 Correct 3 ms 9564 KB Output is correct
15 Correct 2 ms 9564 KB Output is correct
16 Correct 2 ms 9564 KB Output is correct
17 Correct 2 ms 9564 KB Output is correct
18 Correct 3 ms 9564 KB Output is correct
19 Correct 2 ms 9560 KB Output is correct
20 Correct 3 ms 9564 KB Output is correct
21 Correct 3 ms 9560 KB Output is correct
22 Correct 3 ms 9564 KB Output is correct
23 Correct 3 ms 9564 KB Output is correct
24 Correct 3 ms 9560 KB Output is correct
25 Correct 4 ms 9564 KB Output is correct
26 Correct 3 ms 9564 KB Output is correct
27 Correct 2 ms 9560 KB Output is correct
28 Correct 4 ms 9564 KB Output is correct
29 Correct 3 ms 9564 KB Output is correct
30 Correct 3 ms 9564 KB Output is correct
31 Correct 4 ms 9816 KB Output is correct
32 Correct 3 ms 9560 KB Output is correct
33 Correct 3 ms 9564 KB Output is correct
34 Correct 3 ms 9612 KB Output is correct
35 Correct 3 ms 9564 KB Output is correct
36 Correct 3 ms 9564 KB Output is correct
37 Correct 3 ms 9564 KB Output is correct
38 Correct 3 ms 9564 KB Output is correct
39 Correct 141 ms 15196 KB Output is correct
40 Correct 143 ms 15336 KB Output is correct
41 Correct 170 ms 15452 KB Output is correct
42 Correct 151 ms 15620 KB Output is correct
43 Correct 61 ms 15440 KB Output is correct
44 Correct 56 ms 15816 KB Output is correct
45 Correct 130 ms 18256 KB Output is correct
46 Correct 94 ms 21328 KB Output is correct
47 Correct 141 ms 19280 KB Output is correct
48 Correct 225 ms 30484 KB Output is correct
49 Correct 190 ms 29424 KB Output is correct
50 Correct 141 ms 19324 KB Output is correct
51 Correct 141 ms 19284 KB Output is correct
52 Correct 170 ms 19192 KB Output is correct
53 Correct 196 ms 18000 KB Output is correct
54 Correct 124 ms 18156 KB Output is correct
55 Correct 19 ms 10100 KB Output is correct
56 Correct 14 ms 9820 KB Output is correct
57 Correct 115 ms 15672 KB Output is correct
58 Correct 37 ms 15568 KB Output is correct
59 Correct 223 ms 24672 KB Output is correct
60 Correct 675 ms 38540 KB Output is correct
61 Correct 261 ms 19536 KB Output is correct
62 Correct 234 ms 19580 KB Output is correct
63 Correct 279 ms 19284 KB Output is correct
64 Correct 777 ms 23628 KB Output is correct
65 Correct 160 ms 19184 KB Output is correct
66 Correct 414 ms 27900 KB Output is correct
67 Correct 97 ms 19392 KB Output is correct
68 Correct 372 ms 23112 KB Output is correct
69 Correct 297 ms 22864 KB Output is correct
70 Correct 297 ms 22516 KB Output is correct