Submission #890580

# Submission time Handle Problem Language Result Execution time Memory
890580 2023-12-21T13:50:34 Z oblantis Race (IOI11_race) C++17
100 / 100
592 ms 45216 KB
#include <bits/stdc++.h>
#include "race.h"
#define all(v) v.begin(), v.end()
#define pb push_back
#define ss second
#define ff first
#define vt vector
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, int> pdi;
const ll inf = 1e9 + 10000;
const int mod = 1e9+7;
const int maxn = 2e5 + 12;
vector<pii> g[maxn];
int sz[maxn], ans = maxn, k;
bool was[maxn];
void dfs(int v, int pr) {
	sz[v] = 1;
	for(auto i : g[v]) {
		if(!was[i.ff] && i.ff != pr) {
			dfs(i.ff, v);
			sz[v] += sz[i.ff];
		}
	}
}
int fnd(int v, int pr, int n) {
	for(auto i : g[v]) {
		if(!was[i.ff] && i.ff != pr){ 
			if(sz[i.ff] > n / 2) {
				return fnd(i.ff, v, n);
			}
		}
	}
	return v;
}
map<int, int> ok;
vector<pii> upd;
void cnt(int v, int pr, int x, int y) {
	if(x <= k){
		if(ok.find(k - x) != ok.end())ans = min(ans, ok[k - x] + y);
	}
	else x = k + 1;
	sz[v] = 1;
	for(auto i : g[v]) {
		 if(i.ff != pr && !was[i.ff]) {
			cnt(i.ff, v, x + i.ss, y + 1);
			sz[v] += sz[i.ff];
		 }
	}
	upd.pb({x, y});
}
void go(int v, int n) {
	dfs(v, -1);
	int cen = fnd(v, -1, n);
	was[cen] = 1;
	ok.clear();
	ok[0] = 0;
	for(auto i : g[cen]){ 
		if(!was[i.ff]){
			cnt(i.ff, cen, i.ss, 1);
			while(!upd.empty()){
				if(upd.back().ff <= k) {
					if(ok.find(upd.back().ff) == ok.end())ok[upd.back().ff] = upd.back().ss;
					else ok[upd.back().ff] = min(ok[upd.back().ff], upd.back().ss);
				}
				upd.pop_back();
			}
		}
	}
	for(auto i : g[cen]){
		if(!was[i.ff]){
			go(i.ff, sz[i.ff]);
		}
	}
}
int best_path(int n, int K, int h[][2], int l[]){
	k = K;
	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]});
	}
	if(K == 0)ans = 0;
	go(0, n);
	return (ans == maxn ? -1 : ans);
}

# Verdict Execution time Memory Grader output
1 Correct 2 ms 9564 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 9560 KB Output is correct
11 Correct 2 ms 9644 KB Output is correct
12 Correct 2 ms 9564 KB Output is correct
13 Correct 2 ms 9564 KB Output is correct
14 Correct 2 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 2 ms 9564 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 9564 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 9560 KB Output is correct
11 Correct 2 ms 9644 KB Output is correct
12 Correct 2 ms 9564 KB Output is correct
13 Correct 2 ms 9564 KB Output is correct
14 Correct 2 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 2 ms 9564 KB Output is correct
19 Correct 2 ms 9564 KB Output is correct
20 Correct 2 ms 9564 KB Output is correct
21 Correct 3 ms 9820 KB Output is correct
22 Correct 2 ms 9820 KB Output is correct
23 Correct 2 ms 9820 KB Output is correct
24 Correct 3 ms 9820 KB Output is correct
25 Correct 4 ms 9656 KB Output is correct
26 Correct 3 ms 9820 KB Output is correct
27 Correct 2 ms 9820 KB Output is correct
28 Correct 3 ms 9820 KB Output is correct
29 Correct 3 ms 9820 KB Output is correct
30 Correct 3 ms 9816 KB Output is correct
31 Correct 3 ms 9820 KB Output is correct
32 Correct 3 ms 9820 KB Output is correct
33 Correct 3 ms 9864 KB Output is correct
34 Correct 3 ms 10072 KB Output is correct
35 Correct 2 ms 9820 KB Output is correct
36 Correct 3 ms 9820 KB Output is correct
37 Correct 3 ms 9820 KB Output is correct
38 Correct 3 ms 9820 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 9564 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 9560 KB Output is correct
11 Correct 2 ms 9644 KB Output is correct
12 Correct 2 ms 9564 KB Output is correct
13 Correct 2 ms 9564 KB Output is correct
14 Correct 2 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 2 ms 9564 KB Output is correct
19 Correct 141 ms 17628 KB Output is correct
20 Correct 129 ms 17592 KB Output is correct
21 Correct 131 ms 17632 KB Output is correct
22 Correct 132 ms 17544 KB Output is correct
23 Correct 83 ms 17876 KB Output is correct
24 Correct 58 ms 17500 KB Output is correct
25 Correct 119 ms 22484 KB Output is correct
26 Correct 85 ms 24800 KB Output is correct
27 Correct 145 ms 22436 KB Output is correct
28 Correct 264 ms 37916 KB Output is correct
29 Correct 263 ms 36756 KB Output is correct
30 Correct 141 ms 22452 KB Output is correct
31 Correct 142 ms 22456 KB Output is correct
32 Correct 156 ms 22356 KB Output is correct
33 Correct 219 ms 22476 KB Output is correct
34 Correct 164 ms 23240 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 9564 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 9560 KB Output is correct
11 Correct 2 ms 9644 KB Output is correct
12 Correct 2 ms 9564 KB Output is correct
13 Correct 2 ms 9564 KB Output is correct
14 Correct 2 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 2 ms 9564 KB Output is correct
19 Correct 2 ms 9564 KB Output is correct
20 Correct 2 ms 9564 KB Output is correct
21 Correct 3 ms 9820 KB Output is correct
22 Correct 2 ms 9820 KB Output is correct
23 Correct 2 ms 9820 KB Output is correct
24 Correct 3 ms 9820 KB Output is correct
25 Correct 4 ms 9656 KB Output is correct
26 Correct 3 ms 9820 KB Output is correct
27 Correct 2 ms 9820 KB Output is correct
28 Correct 3 ms 9820 KB Output is correct
29 Correct 3 ms 9820 KB Output is correct
30 Correct 3 ms 9816 KB Output is correct
31 Correct 3 ms 9820 KB Output is correct
32 Correct 3 ms 9820 KB Output is correct
33 Correct 3 ms 9864 KB Output is correct
34 Correct 3 ms 10072 KB Output is correct
35 Correct 2 ms 9820 KB Output is correct
36 Correct 3 ms 9820 KB Output is correct
37 Correct 3 ms 9820 KB Output is correct
38 Correct 3 ms 9820 KB Output is correct
39 Correct 141 ms 17628 KB Output is correct
40 Correct 129 ms 17592 KB Output is correct
41 Correct 131 ms 17632 KB Output is correct
42 Correct 132 ms 17544 KB Output is correct
43 Correct 83 ms 17876 KB Output is correct
44 Correct 58 ms 17500 KB Output is correct
45 Correct 119 ms 22484 KB Output is correct
46 Correct 85 ms 24800 KB Output is correct
47 Correct 145 ms 22436 KB Output is correct
48 Correct 264 ms 37916 KB Output is correct
49 Correct 263 ms 36756 KB Output is correct
50 Correct 141 ms 22452 KB Output is correct
51 Correct 142 ms 22456 KB Output is correct
52 Correct 156 ms 22356 KB Output is correct
53 Correct 219 ms 22476 KB Output is correct
54 Correct 164 ms 23240 KB Output is correct
55 Correct 15 ms 10328 KB Output is correct
56 Correct 11 ms 10332 KB Output is correct
57 Correct 104 ms 17724 KB Output is correct
58 Correct 39 ms 16840 KB Output is correct
59 Correct 221 ms 28088 KB Output is correct
60 Correct 592 ms 45216 KB Output is correct
61 Correct 187 ms 22780 KB Output is correct
62 Correct 196 ms 22692 KB Output is correct
63 Correct 231 ms 22832 KB Output is correct
64 Correct 577 ms 27964 KB Output is correct
65 Correct 156 ms 24484 KB Output is correct
66 Correct 417 ms 34248 KB Output is correct
67 Correct 96 ms 23044 KB Output is correct
68 Correct 298 ms 27628 KB Output is correct
69 Correct 270 ms 27612 KB Output is correct
70 Correct 266 ms 27048 KB Output is correct