Submission #398072

# Submission time Handle Problem Language Result Execution time Memory
398072 2021-05-03T15:39:05 Z Antekb Race (IOI11_race) C++14
100 / 100
1051 ms 48420 KB
#include "race.h"
#include<bits/stdc++.h>
using namespace std;
#define st first
#define nd second
#define pb(x) push_back(x)
#define mp(x, y) make_pair(x, y)
typedef vector<int> vi;
typedef long long ll;
typedef pair<int, int> pii;
const int N=2e5+5;
vi w, to, uzy;
vi E[N];
int siz[N], dep[N];
ll d[N];
const int M=1e6+5;
int dist[M], dist2[M], opt[M];
int k, cent, ans=N;
void dfs_siz(int v, int p, int n){
	siz[v]=1;
	bool czy=1;
	for(int i:E[v]){
		if(to[i]!=p && !uzy[i]){
			dfs_siz(to[i], v, n);
			siz[v]+=siz[to[i]];
			if(2*siz[to[i]]>n)czy=0;
		}
	}
	if(2*(n-siz[v])>n)czy=0;
	if(czy)cent=v;
	//cout<<v<<" "<<siz[v]<<"\n";
}
int dfs_calc(int v, int p, int anc){
	//cout<<v<<" "<<dep[v]<<" "<<d[v]<<"\n";
	int res=1;
	if(d[v]<=k && (dist[d[v]]==0 || dist[d[v]]>dep[v])){
		if(opt[d[v]]!=anc)dist2[d[v]]=dist[d[v]];
		dist[d[v]]=dep[v];
		opt[d[v]]=anc;
	}
	if(k>=d[v] && dist[k-d[v]]!=0 && opt[k-d[v]]!=anc)ans=min(ans, dep[v]+dist[k-d[v]]);
	if(k>=d[v] && dist2[k-d[v]]!=0)ans=min(ans, dep[v]+dist2[k-d[v]]);
	if(k==d[v])ans=min(ans, dep[v]);
	for(int i:E[v]){
		if(to[i]!=p && !uzy[i]){
			dep[to[i]]=dep[v]+1;
			d[to[i]]=d[v]+w[i];
			res+=dfs_calc(to[i], v, anc);
		}
	}
	return res;
}
void dfs_clear(int v, int p){
	if(d[v]<=k){
		dist[d[v]]=dist2[d[v]]=opt[d[v]]=0;
	}
	for(int i:E[v]){
		if(!uzy[i] && to[i]!=p){
			dfs_clear(to[i], v);
		}
	}
}
void decomp(int v, int n){
	//cout<<v<<" "<<n<<"a\n";
	if(n==1)return;
	cent=-1;
	dfs_siz(v, 0, n);
	assert(cent>0);
	//cout<<cent<<"\n";
	for(int i:E[cent]){
		if(!uzy[i]){
			dep[to[i]]=1;
			d[to[i]]=w[i];
			siz[to[i]]=dfs_calc(to[i], cent, to[i]);
		}
	}
	int C=cent;
	dfs_clear(C, 0);
	for(int i:E[C]){
		if(!uzy[i]){
			uzy[i]=1;
			uzy[i^1]=1;
			decomp(to[i], siz[to[i]]);
		}
	}
}
int best_path(int n, int _k, int H[][2], int L[])
{
	k=_k;
	for(int i=0; i<n-1; i++){
		H[i][0]++;
		H[i][1]++;
		E[H[i][0]].pb(to.size());
		to.pb(H[i][1]);
		E[H[i][1]].pb(to.size());
		to.pb(H[i][0]);
		w.pb(L[i]);
		w.pb(L[i]);
	}
	uzy.resize(w.size());
	decomp(1, n);
	return ((ans==N) ? -1 : ans);
}

# Verdict Execution time Memory Grader output
1 Correct 3 ms 5068 KB Output is correct
2 Correct 3 ms 5068 KB Output is correct
3 Correct 3 ms 5036 KB Output is correct
4 Correct 3 ms 5068 KB Output is correct
5 Correct 3 ms 5068 KB Output is correct
6 Correct 3 ms 5068 KB Output is correct
7 Correct 3 ms 5068 KB Output is correct
8 Correct 3 ms 5068 KB Output is correct
9 Correct 3 ms 5068 KB Output is correct
10 Correct 3 ms 5068 KB Output is correct
11 Correct 3 ms 5068 KB Output is correct
12 Correct 4 ms 5072 KB Output is correct
13 Correct 3 ms 5068 KB Output is correct
14 Correct 3 ms 5068 KB Output is correct
15 Correct 3 ms 5068 KB Output is correct
16 Correct 3 ms 5068 KB Output is correct
17 Correct 3 ms 5068 KB Output is correct
18 Correct 3 ms 5068 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 5068 KB Output is correct
2 Correct 3 ms 5068 KB Output is correct
3 Correct 3 ms 5036 KB Output is correct
4 Correct 3 ms 5068 KB Output is correct
5 Correct 3 ms 5068 KB Output is correct
6 Correct 3 ms 5068 KB Output is correct
7 Correct 3 ms 5068 KB Output is correct
8 Correct 3 ms 5068 KB Output is correct
9 Correct 3 ms 5068 KB Output is correct
10 Correct 3 ms 5068 KB Output is correct
11 Correct 3 ms 5068 KB Output is correct
12 Correct 4 ms 5072 KB Output is correct
13 Correct 3 ms 5068 KB Output is correct
14 Correct 3 ms 5068 KB Output is correct
15 Correct 3 ms 5068 KB Output is correct
16 Correct 3 ms 5068 KB Output is correct
17 Correct 3 ms 5068 KB Output is correct
18 Correct 3 ms 5068 KB Output is correct
19 Correct 3 ms 4940 KB Output is correct
20 Correct 3 ms 5068 KB Output is correct
21 Correct 4 ms 5068 KB Output is correct
22 Correct 8 ms 12620 KB Output is correct
23 Correct 8 ms 11596 KB Output is correct
24 Correct 9 ms 13772 KB Output is correct
25 Correct 8 ms 10316 KB Output is correct
26 Correct 6 ms 9020 KB Output is correct
27 Correct 4 ms 5068 KB Output is correct
28 Correct 5 ms 7372 KB Output is correct
29 Correct 6 ms 8816 KB Output is correct
30 Correct 6 ms 9292 KB Output is correct
31 Correct 7 ms 10572 KB Output is correct
32 Correct 8 ms 10620 KB Output is correct
33 Correct 9 ms 13004 KB Output is correct
34 Correct 8 ms 11904 KB Output is correct
35 Correct 9 ms 13820 KB Output is correct
36 Correct 9 ms 14796 KB Output is correct
37 Correct 8 ms 10828 KB Output is correct
38 Correct 6 ms 8524 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 5068 KB Output is correct
2 Correct 3 ms 5068 KB Output is correct
3 Correct 3 ms 5036 KB Output is correct
4 Correct 3 ms 5068 KB Output is correct
5 Correct 3 ms 5068 KB Output is correct
6 Correct 3 ms 5068 KB Output is correct
7 Correct 3 ms 5068 KB Output is correct
8 Correct 3 ms 5068 KB Output is correct
9 Correct 3 ms 5068 KB Output is correct
10 Correct 3 ms 5068 KB Output is correct
11 Correct 3 ms 5068 KB Output is correct
12 Correct 4 ms 5072 KB Output is correct
13 Correct 3 ms 5068 KB Output is correct
14 Correct 3 ms 5068 KB Output is correct
15 Correct 3 ms 5068 KB Output is correct
16 Correct 3 ms 5068 KB Output is correct
17 Correct 3 ms 5068 KB Output is correct
18 Correct 3 ms 5068 KB Output is correct
19 Correct 259 ms 13328 KB Output is correct
20 Correct 272 ms 13332 KB Output is correct
21 Correct 258 ms 13248 KB Output is correct
22 Correct 231 ms 13356 KB Output is correct
23 Correct 150 ms 13272 KB Output is correct
24 Correct 92 ms 13484 KB Output is correct
25 Correct 181 ms 17320 KB Output is correct
26 Correct 124 ms 21224 KB Output is correct
27 Correct 293 ms 22052 KB Output is correct
28 Correct 504 ms 37148 KB Output is correct
29 Correct 506 ms 38936 KB Output is correct
30 Correct 299 ms 25104 KB Output is correct
31 Correct 291 ms 24936 KB Output is correct
32 Correct 434 ms 25312 KB Output is correct
33 Correct 383 ms 24480 KB Output is correct
34 Correct 389 ms 25472 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 5068 KB Output is correct
2 Correct 3 ms 5068 KB Output is correct
3 Correct 3 ms 5036 KB Output is correct
4 Correct 3 ms 5068 KB Output is correct
5 Correct 3 ms 5068 KB Output is correct
6 Correct 3 ms 5068 KB Output is correct
7 Correct 3 ms 5068 KB Output is correct
8 Correct 3 ms 5068 KB Output is correct
9 Correct 3 ms 5068 KB Output is correct
10 Correct 3 ms 5068 KB Output is correct
11 Correct 3 ms 5068 KB Output is correct
12 Correct 4 ms 5072 KB Output is correct
13 Correct 3 ms 5068 KB Output is correct
14 Correct 3 ms 5068 KB Output is correct
15 Correct 3 ms 5068 KB Output is correct
16 Correct 3 ms 5068 KB Output is correct
17 Correct 3 ms 5068 KB Output is correct
18 Correct 3 ms 5068 KB Output is correct
19 Correct 3 ms 4940 KB Output is correct
20 Correct 3 ms 5068 KB Output is correct
21 Correct 4 ms 5068 KB Output is correct
22 Correct 8 ms 12620 KB Output is correct
23 Correct 8 ms 11596 KB Output is correct
24 Correct 9 ms 13772 KB Output is correct
25 Correct 8 ms 10316 KB Output is correct
26 Correct 6 ms 9020 KB Output is correct
27 Correct 4 ms 5068 KB Output is correct
28 Correct 5 ms 7372 KB Output is correct
29 Correct 6 ms 8816 KB Output is correct
30 Correct 6 ms 9292 KB Output is correct
31 Correct 7 ms 10572 KB Output is correct
32 Correct 8 ms 10620 KB Output is correct
33 Correct 9 ms 13004 KB Output is correct
34 Correct 8 ms 11904 KB Output is correct
35 Correct 9 ms 13820 KB Output is correct
36 Correct 9 ms 14796 KB Output is correct
37 Correct 8 ms 10828 KB Output is correct
38 Correct 6 ms 8524 KB Output is correct
39 Correct 259 ms 13328 KB Output is correct
40 Correct 272 ms 13332 KB Output is correct
41 Correct 258 ms 13248 KB Output is correct
42 Correct 231 ms 13356 KB Output is correct
43 Correct 150 ms 13272 KB Output is correct
44 Correct 92 ms 13484 KB Output is correct
45 Correct 181 ms 17320 KB Output is correct
46 Correct 124 ms 21224 KB Output is correct
47 Correct 293 ms 22052 KB Output is correct
48 Correct 504 ms 37148 KB Output is correct
49 Correct 506 ms 38936 KB Output is correct
50 Correct 299 ms 25104 KB Output is correct
51 Correct 291 ms 24936 KB Output is correct
52 Correct 434 ms 25312 KB Output is correct
53 Correct 383 ms 24480 KB Output is correct
54 Correct 389 ms 25472 KB Output is correct
55 Correct 16 ms 6168 KB Output is correct
56 Correct 16 ms 6040 KB Output is correct
57 Correct 114 ms 14524 KB Output is correct
58 Correct 46 ms 14688 KB Output is correct
59 Correct 137 ms 23720 KB Output is correct
60 Correct 587 ms 46208 KB Output is correct
61 Correct 344 ms 25264 KB Output is correct
62 Correct 347 ms 25160 KB Output is correct
63 Correct 491 ms 25204 KB Output is correct
64 Correct 1051 ms 28316 KB Output is correct
65 Correct 682 ms 25560 KB Output is correct
66 Correct 688 ms 48420 KB Output is correct
67 Correct 139 ms 25612 KB Output is correct
68 Correct 519 ms 33524 KB Output is correct
69 Correct 513 ms 33824 KB Output is correct
70 Correct 508 ms 32464 KB Output is correct