Submission #520298

# Submission time Handle Problem Language Result Execution time Memory
520298 2022-01-29T08:30:09 Z new_acc Race (IOI11_race) C++14
100 / 100
670 ms 52008 KB
#include<bits/stdc++.h>
#define ll long long
#define fi first
#define se second
using namespace std;
const int N=2e5+10;
vector<pair<int,int> >graf[N];
int pod[N];
pair<pair<int,int>,pair<int,int> >t[1000*1000+10];
bool vis[N];
int cn;
int res=INT_MAX;
int dfspod(int v,int o){
	int res=0;
	for(auto u:graf[v]){
		if(vis[u.fi]||u.fi==o) continue;
		res+=dfspod(u.fi,v);
	}	
	return res+1;
}
void dfs(int v,int o,int s){
	bool b=1;
	pod[v]=0;
	for(auto u:graf[v]){
		if(vis[u.fi]||o==u.fi) continue;
		dfs(u.fi,v,s);
		pod[v]+=pod[u.fi];
		if(pod[u.fi]>s/2) b=0;
	}
	pod[v]++;
	if(s-pod[v]>s/2) b=0;
	if(b) cn=v;
} 
void dfs2(int v,int o,int g,int odl,bool b,int k){
	if(g>1000*1000) return;
	if(b==0) t[g].fi.fi=0,t[g].fi.se=0,t[g].se.fi=0,t[g].se.se=0;
	else if(t[g].fi.fi>odl||t[g].fi.fi==0) t[g].fi={odl,k};
	for(auto u:graf[v]){
		if(vis[u.fi]||o==u.fi) continue;
		dfs2(u.fi,v,g+u.se,odl+1,b,k);
	}
}
void dfs3(int v,int o,int g,int odl,int k){
	if(g>1000*1000) return;
	if(t[g].fi.se!=k&&(t[g].se.fi>odl||t[g].se.fi==0)) t[g].se={odl,k};
	for(auto u:graf[v]){
		if(vis[u.fi]||o==u.fi) continue;
		dfs3(u.fi,v,g+u.se,odl+1,k);
	}	
}
void dfs_wyn(int v,int o,int g,int odl,int k,int kk){
	if(g>k) return;
	if(g==k) res=min(res,odl);
	if(t[k-g].fi.se!=kk&&t[k-g].fi.fi!=0) res=min(res,t[k-g].fi.fi+odl);
	if(t[k-g].se.se!=kk&&t[k-g].se.fi!=0) res=min(res,t[k-g].se.fi+odl);
	for(auto u:graf[v]){
		if(vis[u.fi]||o==u.fi) continue;
		dfs_wyn(u.fi,v,g+u.se,odl+1,k,kk);
	}
}
void decomp(int v,int k){
	if(vis[v]) return;
	int s=dfspod(v,v);
	dfs(v,v,s);
	for(auto u:graf[cn]){
		if(vis[u.fi]) continue;
		dfs2(u.fi,cn,u.se,1,1,u.fi);
	}
	for(auto u:graf[cn]){
		if(vis[u.fi]) continue;
		dfs3(u.fi,cn,u.se,1,u.fi);
	}
	for(auto u:graf[cn]){
		if(vis[u.fi]) continue;
		dfs_wyn(u.fi,cn,u.se,1,k,u.fi);
	}
	for(auto u:graf[cn]){
		if(vis[u.fi]) continue;
		dfs2(u.fi,cn,u.se,1,0,u.fi);
	}
	int cc=cn;
	vis[cc]=1;
	for(auto u:graf[cc]) decomp(u.fi,k);
}
int best_path(int n,int k,int h[][2],int l[]){
	for(int i=0;i<=n-2;i++) h[i][0]++,h[i][1]++,graf[h[i][0]].push_back({h[i][1],l[i]}),graf[h[i][1]].push_back({h[i][0],l[i]});
	decomp(1,k);
	if(res==INT_MAX) return -1;
	return res;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4940 KB Output is correct
2 Correct 3 ms 4940 KB Output is correct
3 Correct 2 ms 4996 KB Output is correct
4 Correct 3 ms 4996 KB Output is correct
5 Correct 3 ms 4940 KB Output is correct
6 Correct 4 ms 4996 KB Output is correct
7 Correct 2 ms 5068 KB Output is correct
8 Correct 3 ms 5068 KB Output is correct
9 Correct 3 ms 4940 KB Output is correct
10 Correct 3 ms 5000 KB Output is correct
11 Correct 3 ms 4996 KB Output is correct
12 Correct 3 ms 4996 KB Output is correct
13 Correct 3 ms 5004 KB Output is correct
14 Correct 3 ms 4996 KB Output is correct
15 Correct 3 ms 4940 KB Output is correct
16 Correct 3 ms 4940 KB Output is correct
17 Correct 3 ms 4940 KB Output is correct
18 Correct 3 ms 4940 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4940 KB Output is correct
2 Correct 3 ms 4940 KB Output is correct
3 Correct 2 ms 4996 KB Output is correct
4 Correct 3 ms 4996 KB Output is correct
5 Correct 3 ms 4940 KB Output is correct
6 Correct 4 ms 4996 KB Output is correct
7 Correct 2 ms 5068 KB Output is correct
8 Correct 3 ms 5068 KB Output is correct
9 Correct 3 ms 4940 KB Output is correct
10 Correct 3 ms 5000 KB Output is correct
11 Correct 3 ms 4996 KB Output is correct
12 Correct 3 ms 4996 KB Output is correct
13 Correct 3 ms 5004 KB Output is correct
14 Correct 3 ms 4996 KB Output is correct
15 Correct 3 ms 4940 KB Output is correct
16 Correct 3 ms 4940 KB Output is correct
17 Correct 3 ms 4940 KB Output is correct
18 Correct 3 ms 4940 KB Output is correct
19 Correct 3 ms 4992 KB Output is correct
20 Correct 3 ms 4940 KB Output is correct
21 Correct 4 ms 5012 KB Output is correct
22 Correct 7 ms 9488 KB Output is correct
23 Correct 7 ms 10004 KB Output is correct
24 Correct 7 ms 10772 KB Output is correct
25 Correct 8 ms 10564 KB Output is correct
26 Correct 10 ms 14484 KB Output is correct
27 Correct 4 ms 5012 KB Output is correct
28 Correct 7 ms 9804 KB Output is correct
29 Correct 7 ms 10216 KB Output is correct
30 Correct 6 ms 10256 KB Output is correct
31 Correct 8 ms 10700 KB Output is correct
32 Correct 9 ms 10828 KB Output is correct
33 Correct 11 ms 13076 KB Output is correct
34 Correct 9 ms 13644 KB Output is correct
35 Correct 9 ms 13324 KB Output is correct
36 Correct 9 ms 13068 KB Output is correct
37 Correct 7 ms 10060 KB Output is correct
38 Correct 6 ms 8780 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4940 KB Output is correct
2 Correct 3 ms 4940 KB Output is correct
3 Correct 2 ms 4996 KB Output is correct
4 Correct 3 ms 4996 KB Output is correct
5 Correct 3 ms 4940 KB Output is correct
6 Correct 4 ms 4996 KB Output is correct
7 Correct 2 ms 5068 KB Output is correct
8 Correct 3 ms 5068 KB Output is correct
9 Correct 3 ms 4940 KB Output is correct
10 Correct 3 ms 5000 KB Output is correct
11 Correct 3 ms 4996 KB Output is correct
12 Correct 3 ms 4996 KB Output is correct
13 Correct 3 ms 5004 KB Output is correct
14 Correct 3 ms 4996 KB Output is correct
15 Correct 3 ms 4940 KB Output is correct
16 Correct 3 ms 4940 KB Output is correct
17 Correct 3 ms 4940 KB Output is correct
18 Correct 3 ms 4940 KB Output is correct
19 Correct 192 ms 11584 KB Output is correct
20 Correct 204 ms 11672 KB Output is correct
21 Correct 190 ms 11656 KB Output is correct
22 Correct 171 ms 11816 KB Output is correct
23 Correct 134 ms 11916 KB Output is correct
24 Correct 76 ms 11796 KB Output is correct
25 Correct 187 ms 16104 KB Output is correct
26 Correct 121 ms 20420 KB Output is correct
27 Correct 297 ms 18852 KB Output is correct
28 Correct 496 ms 52008 KB Output is correct
29 Correct 516 ms 50756 KB Output is correct
30 Correct 234 ms 18920 KB Output is correct
31 Correct 223 ms 18756 KB Output is correct
32 Correct 333 ms 19032 KB Output is correct
33 Correct 333 ms 17744 KB Output is correct
34 Correct 268 ms 34244 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4940 KB Output is correct
2 Correct 3 ms 4940 KB Output is correct
3 Correct 2 ms 4996 KB Output is correct
4 Correct 3 ms 4996 KB Output is correct
5 Correct 3 ms 4940 KB Output is correct
6 Correct 4 ms 4996 KB Output is correct
7 Correct 2 ms 5068 KB Output is correct
8 Correct 3 ms 5068 KB Output is correct
9 Correct 3 ms 4940 KB Output is correct
10 Correct 3 ms 5000 KB Output is correct
11 Correct 3 ms 4996 KB Output is correct
12 Correct 3 ms 4996 KB Output is correct
13 Correct 3 ms 5004 KB Output is correct
14 Correct 3 ms 4996 KB Output is correct
15 Correct 3 ms 4940 KB Output is correct
16 Correct 3 ms 4940 KB Output is correct
17 Correct 3 ms 4940 KB Output is correct
18 Correct 3 ms 4940 KB Output is correct
19 Correct 3 ms 4992 KB Output is correct
20 Correct 3 ms 4940 KB Output is correct
21 Correct 4 ms 5012 KB Output is correct
22 Correct 7 ms 9488 KB Output is correct
23 Correct 7 ms 10004 KB Output is correct
24 Correct 7 ms 10772 KB Output is correct
25 Correct 8 ms 10564 KB Output is correct
26 Correct 10 ms 14484 KB Output is correct
27 Correct 4 ms 5012 KB Output is correct
28 Correct 7 ms 9804 KB Output is correct
29 Correct 7 ms 10216 KB Output is correct
30 Correct 6 ms 10256 KB Output is correct
31 Correct 8 ms 10700 KB Output is correct
32 Correct 9 ms 10828 KB Output is correct
33 Correct 11 ms 13076 KB Output is correct
34 Correct 9 ms 13644 KB Output is correct
35 Correct 9 ms 13324 KB Output is correct
36 Correct 9 ms 13068 KB Output is correct
37 Correct 7 ms 10060 KB Output is correct
38 Correct 6 ms 8780 KB Output is correct
39 Correct 192 ms 11584 KB Output is correct
40 Correct 204 ms 11672 KB Output is correct
41 Correct 190 ms 11656 KB Output is correct
42 Correct 171 ms 11816 KB Output is correct
43 Correct 134 ms 11916 KB Output is correct
44 Correct 76 ms 11796 KB Output is correct
45 Correct 187 ms 16104 KB Output is correct
46 Correct 121 ms 20420 KB Output is correct
47 Correct 297 ms 18852 KB Output is correct
48 Correct 496 ms 52008 KB Output is correct
49 Correct 516 ms 50756 KB Output is correct
50 Correct 234 ms 18920 KB Output is correct
51 Correct 223 ms 18756 KB Output is correct
52 Correct 333 ms 19032 KB Output is correct
53 Correct 333 ms 17744 KB Output is correct
54 Correct 268 ms 34244 KB Output is correct
55 Correct 14 ms 5836 KB Output is correct
56 Correct 15 ms 5580 KB Output is correct
57 Correct 111 ms 11896 KB Output is correct
58 Correct 36 ms 11648 KB Output is correct
59 Correct 135 ms 22076 KB Output is correct
60 Correct 605 ms 44696 KB Output is correct
61 Correct 247 ms 19476 KB Output is correct
62 Correct 232 ms 18872 KB Output is correct
63 Correct 329 ms 19008 KB Output is correct
64 Correct 670 ms 23304 KB Output is correct
65 Correct 283 ms 35268 KB Output is correct
66 Correct 472 ms 47740 KB Output is correct
67 Correct 102 ms 19552 KB Output is correct
68 Correct 331 ms 30192 KB Output is correct
69 Correct 338 ms 30700 KB Output is correct
70 Correct 348 ms 29380 KB Output is correct