Submission #540593

# Submission time Handle Problem Language Result Execution time Memory
540593 2022-03-21T05:41:33 Z jamezzz Race (IOI11_race) C++17
100 / 100
600 ms 61024 KB
#include "race.h"
#include <bits/stdc++.h>
using namespace std;

#ifdef DEBUG
#define dbg(...) printf(__VA_ARGS__);
#define getchar_unlocked getchar
#else
#define dbg(...)
#endif
#define sf scanf
#define pf printf
#define fi first
#define se second
#define pb push_back
#define sz(x) (int)x.size()
#define mnto(x,y) x=min(x,(__typeof__(x))y)
#define mxto(x,y) x=max(x,(__typeof__(x))y)
#define INF 1023456789
#define LINF 1023456789123456789
#define all(x) x.begin(), x.end()
#define disc(x) sort(all(x));x.resize(unique(all(x))-x.begin());
typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef pair<ll, ll> pll;
typedef tuple<int, int, int> iii;
typedef tuple<int, int, int, int> iiii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<pll> vll;
mt19937 rng(time(0));

#define mod 1000000007

#define maxn 200005

int N,K,ans=INF,sub[maxn],dis[maxn],num[maxn],mn[1000005];
bool mark[maxn];
vi nodes[maxn];
vii AL[maxn];

void dfs(int u,int p){
	sub[u]=1;
	for(auto[v,w]:AL[u]){
		if(mark[v]||v==p)continue;
		dfs(v,u);
		sub[u]+=sub[v];
	}
}

void dfs2(int u,int p,int s){
	if(s!=-1)nodes[s].pb(u);
	for(auto[v,w]:AL[u]){
		if(mark[v]||v==p)continue;
		dis[v]=dis[u]+w;
		if(dis[v]>=INF)dis[v]=INF;
		num[v]=num[u]+1;
		if(s==-1){
			nodes[v].clear();
			dfs2(v,u,v);
		}
		else dfs2(v,u,s);
	}
}

void decomp(int u){
	sub[u]=0;
	dfs(u,-1);
	int c=u;
	while(true){
		bool val=true;
		for(auto[v,w]:AL[c]){
			if(!mark[v]&&sub[v]<sub[c]&&sub[v]>sub[u]/2){
				val=false;
				c=v;break;
			}
		}
		if(val)break;
	}
	
	dis[c]=0;num[c]=0;
	dfs2(c,-1,-1);
	for(auto[v,w]:AL[c]){
		if(mark[v])continue;
		for(int i:nodes[v]){
			if(dis[i]>K)continue;
			ans=min(ans,mn[K-dis[i]]+num[i]);
		}
		for(int i:nodes[v]){
			if(dis[i]>K)continue;
			mn[dis[i]]=min(mn[dis[i]],num[i]);
		}
	}
	ans=min(ans,mn[K]);
	
	for(auto[v,w]:AL[c]){
		for(int i:nodes[v]){
			if(dis[i]>K)continue;
			mn[dis[i]]=INF;
		}
	}
	
	mark[c]=true;
	for(auto[v,w]:AL[c]){
		if(!mark[v])decomp(v);
	}
}

int best_path(int _N,int _K,int H[][2],int L[]){
	N=_N;K=_K;
	for(int i=0;i<=1000000;++i)mn[i]=INF;
	for(int i=0;i<N-1;++i){
		AL[H[i][0]].pb({H[i][1],L[i]});
		AL[H[i][1]].pb({H[i][0],L[i]});
	}
	decomp(0);
	return (ans!=INF)?ans:-1;
}

# Verdict Execution time Memory Grader output
1 Correct 8 ms 13652 KB Output is correct
2 Correct 7 ms 13656 KB Output is correct
3 Correct 8 ms 13652 KB Output is correct
4 Correct 8 ms 13560 KB Output is correct
5 Correct 8 ms 13652 KB Output is correct
6 Correct 7 ms 13652 KB Output is correct
7 Correct 8 ms 13668 KB Output is correct
8 Correct 7 ms 13560 KB Output is correct
9 Correct 8 ms 13560 KB Output is correct
10 Correct 7 ms 13652 KB Output is correct
11 Correct 8 ms 13652 KB Output is correct
12 Correct 9 ms 13668 KB Output is correct
13 Correct 7 ms 13556 KB Output is correct
14 Correct 8 ms 13548 KB Output is correct
15 Correct 8 ms 13652 KB Output is correct
16 Correct 7 ms 13652 KB Output is correct
17 Correct 8 ms 13652 KB Output is correct
18 Correct 8 ms 13564 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 13652 KB Output is correct
2 Correct 7 ms 13656 KB Output is correct
3 Correct 8 ms 13652 KB Output is correct
4 Correct 8 ms 13560 KB Output is correct
5 Correct 8 ms 13652 KB Output is correct
6 Correct 7 ms 13652 KB Output is correct
7 Correct 8 ms 13668 KB Output is correct
8 Correct 7 ms 13560 KB Output is correct
9 Correct 8 ms 13560 KB Output is correct
10 Correct 7 ms 13652 KB Output is correct
11 Correct 8 ms 13652 KB Output is correct
12 Correct 9 ms 13668 KB Output is correct
13 Correct 7 ms 13556 KB Output is correct
14 Correct 8 ms 13548 KB Output is correct
15 Correct 8 ms 13652 KB Output is correct
16 Correct 7 ms 13652 KB Output is correct
17 Correct 8 ms 13652 KB Output is correct
18 Correct 8 ms 13564 KB Output is correct
19 Correct 8 ms 13652 KB Output is correct
20 Correct 8 ms 13556 KB Output is correct
21 Correct 8 ms 13652 KB Output is correct
22 Correct 8 ms 13696 KB Output is correct
23 Correct 8 ms 13652 KB Output is correct
24 Correct 8 ms 13652 KB Output is correct
25 Correct 8 ms 13652 KB Output is correct
26 Correct 9 ms 13656 KB Output is correct
27 Correct 8 ms 13680 KB Output is correct
28 Correct 8 ms 13700 KB Output is correct
29 Correct 8 ms 13696 KB Output is correct
30 Correct 9 ms 13700 KB Output is correct
31 Correct 9 ms 13780 KB Output is correct
32 Correct 9 ms 13704 KB Output is correct
33 Correct 9 ms 13700 KB Output is correct
34 Correct 8 ms 13780 KB Output is correct
35 Correct 9 ms 13652 KB Output is correct
36 Correct 9 ms 13780 KB Output is correct
37 Correct 9 ms 13652 KB Output is correct
38 Correct 9 ms 13652 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 13652 KB Output is correct
2 Correct 7 ms 13656 KB Output is correct
3 Correct 8 ms 13652 KB Output is correct
4 Correct 8 ms 13560 KB Output is correct
5 Correct 8 ms 13652 KB Output is correct
6 Correct 7 ms 13652 KB Output is correct
7 Correct 8 ms 13668 KB Output is correct
8 Correct 7 ms 13560 KB Output is correct
9 Correct 8 ms 13560 KB Output is correct
10 Correct 7 ms 13652 KB Output is correct
11 Correct 8 ms 13652 KB Output is correct
12 Correct 9 ms 13668 KB Output is correct
13 Correct 7 ms 13556 KB Output is correct
14 Correct 8 ms 13548 KB Output is correct
15 Correct 8 ms 13652 KB Output is correct
16 Correct 7 ms 13652 KB Output is correct
17 Correct 8 ms 13652 KB Output is correct
18 Correct 8 ms 13564 KB Output is correct
19 Correct 202 ms 27464 KB Output is correct
20 Correct 202 ms 27388 KB Output is correct
21 Correct 197 ms 27400 KB Output is correct
22 Correct 179 ms 26608 KB Output is correct
23 Correct 155 ms 29292 KB Output is correct
24 Correct 118 ms 26408 KB Output is correct
25 Correct 212 ms 33132 KB Output is correct
26 Correct 114 ms 36720 KB Output is correct
27 Correct 210 ms 38044 KB Output is correct
28 Correct 496 ms 61024 KB Output is correct
29 Correct 492 ms 59908 KB Output is correct
30 Correct 218 ms 38016 KB Output is correct
31 Correct 211 ms 38052 KB Output is correct
32 Correct 314 ms 38128 KB Output is correct
33 Correct 356 ms 42468 KB Output is correct
34 Correct 347 ms 42976 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 13652 KB Output is correct
2 Correct 7 ms 13656 KB Output is correct
3 Correct 8 ms 13652 KB Output is correct
4 Correct 8 ms 13560 KB Output is correct
5 Correct 8 ms 13652 KB Output is correct
6 Correct 7 ms 13652 KB Output is correct
7 Correct 8 ms 13668 KB Output is correct
8 Correct 7 ms 13560 KB Output is correct
9 Correct 8 ms 13560 KB Output is correct
10 Correct 7 ms 13652 KB Output is correct
11 Correct 8 ms 13652 KB Output is correct
12 Correct 9 ms 13668 KB Output is correct
13 Correct 7 ms 13556 KB Output is correct
14 Correct 8 ms 13548 KB Output is correct
15 Correct 8 ms 13652 KB Output is correct
16 Correct 7 ms 13652 KB Output is correct
17 Correct 8 ms 13652 KB Output is correct
18 Correct 8 ms 13564 KB Output is correct
19 Correct 8 ms 13652 KB Output is correct
20 Correct 8 ms 13556 KB Output is correct
21 Correct 8 ms 13652 KB Output is correct
22 Correct 8 ms 13696 KB Output is correct
23 Correct 8 ms 13652 KB Output is correct
24 Correct 8 ms 13652 KB Output is correct
25 Correct 8 ms 13652 KB Output is correct
26 Correct 9 ms 13656 KB Output is correct
27 Correct 8 ms 13680 KB Output is correct
28 Correct 8 ms 13700 KB Output is correct
29 Correct 8 ms 13696 KB Output is correct
30 Correct 9 ms 13700 KB Output is correct
31 Correct 9 ms 13780 KB Output is correct
32 Correct 9 ms 13704 KB Output is correct
33 Correct 9 ms 13700 KB Output is correct
34 Correct 8 ms 13780 KB Output is correct
35 Correct 9 ms 13652 KB Output is correct
36 Correct 9 ms 13780 KB Output is correct
37 Correct 9 ms 13652 KB Output is correct
38 Correct 9 ms 13652 KB Output is correct
39 Correct 202 ms 27464 KB Output is correct
40 Correct 202 ms 27388 KB Output is correct
41 Correct 197 ms 27400 KB Output is correct
42 Correct 179 ms 26608 KB Output is correct
43 Correct 155 ms 29292 KB Output is correct
44 Correct 118 ms 26408 KB Output is correct
45 Correct 212 ms 33132 KB Output is correct
46 Correct 114 ms 36720 KB Output is correct
47 Correct 210 ms 38044 KB Output is correct
48 Correct 496 ms 61024 KB Output is correct
49 Correct 492 ms 59908 KB Output is correct
50 Correct 218 ms 38016 KB Output is correct
51 Correct 211 ms 38052 KB Output is correct
52 Correct 314 ms 38128 KB Output is correct
53 Correct 356 ms 42468 KB Output is correct
54 Correct 347 ms 42976 KB Output is correct
55 Correct 17 ms 14804 KB Output is correct
56 Correct 18 ms 14848 KB Output is correct
57 Correct 121 ms 29036 KB Output is correct
58 Correct 48 ms 24180 KB Output is correct
59 Correct 116 ms 36776 KB Output is correct
60 Correct 539 ms 60244 KB Output is correct
61 Correct 228 ms 38232 KB Output is correct
62 Correct 236 ms 37980 KB Output is correct
63 Correct 329 ms 38088 KB Output is correct
64 Correct 544 ms 42692 KB Output is correct
65 Correct 424 ms 40980 KB Output is correct
66 Correct 600 ms 57376 KB Output is correct
67 Correct 200 ms 36008 KB Output is correct
68 Correct 362 ms 38708 KB Output is correct
69 Correct 321 ms 38856 KB Output is correct
70 Correct 321 ms 37592 KB Output is correct