Submission #133098

# Submission time Handle Problem Language Result Execution time Memory
133098 2019-07-20T07:24:34 Z baluteshih Race (IOI11_race) C++14
100 / 100
615 ms 39424 KB
#include "race.h"
#include <bits/stdc++.h>
#define jizz ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define pb push_back
#define ET cout << "\n"
#define MEM(i,j) memset(i,j,sizeof i)
#define F first
#define S second
#define MP make_pair
#define ALL(v) v.begin(),v.end()
#define DB(a,s,e) {for(int i=s;i<e;++i) cout << a[i] << " ";ET;}
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
 
bitset<200005> vis;
vector<pii> G[200005];
const int INF=1e9;
int ans=INF,k,wei,w[200005],tmp[1000005];
 
void center(int u,int f,int &cent,int sz)
{
	int x=0;
	w[u]=1;
	for(pii i:G[u])
		if(i.F!=f&&!vis[i.F])
			center(i.F,u,cent,sz),x=max(x,w[i.F]),w[u]+=w[i.F];
	x=max(x,sz-w[u]);
	if(x<wei) wei=x,cent=u;
}
 
void dfs(int u,int f,int d,int r,vector<pii> &v)
{
	v.pb(MP(d,r));
	for(pii i:G[u])
		if(i.F!=f&&!vis[i.F])
			dfs(i.F,u,d+i.S,r+1,v);
}
 
void cut(int u,int sz)
{
	int c;
	wei=INF,center(u,u,c,sz);
	vis[c]=1;
	for(pii i:G[c])
		if(!vis[i.F])
			if(w[i.F]>w[c]) cut(u,w[u]-w[c]);
			else cut(i.F,w[i.F]);
	vector<int> rv;
	for(pii i:G[c])
		if(!vis[i.F])
		{
			vector<pii> v;
			dfs(i.F,i.F,i.S,1,v);
			for(pii j:v)
				if(j.F<=k&&tmp[k-j.F]!=INF)
					ans=min(ans,j.S+tmp[k-j.F]);
			for(pii j:v)
				if(j.F<=k) 
					if(tmp[j.F]==INF) tmp[j.F]=j.S,rv.pb(j.F);
					else tmp[j.F]=min(tmp[j.F],j.S);
		}
	for(int i:rv)
		tmp[i]=INF;
	vis[c]=0;
}
 
 
int best_path(int N, int K, int H[][2], int L[])
{
	k=K,tmp[0]=0;
	for(int i=1;i<=K;++i)
		tmp[i]=INF;
	for(int i=0;i<N-1;++i)
		G[H[i][0]].pb(MP(H[i][1],L[i])),G[H[i][1]].pb(MP(H[i][0],L[i]));
	cut(0,N);
	if(ans==INF) return -1;
	return ans;
}

Compilation message

race.cpp: In function 'void cut(int, int)':
race.cpp:47:5: warning: suggest explicit braces to avoid ambiguous 'else' [-Wdangling-else]
   if(!vis[i.F])
     ^
race.cpp:60:7: warning: suggest explicit braces to avoid ambiguous 'else' [-Wdangling-else]
     if(j.F<=k) 
       ^
# Verdict Execution time Memory Grader output
1 Correct 6 ms 5112 KB Output is correct
2 Correct 7 ms 5112 KB Output is correct
3 Correct 8 ms 4984 KB Output is correct
4 Correct 8 ms 5112 KB Output is correct
5 Correct 6 ms 5112 KB Output is correct
6 Correct 6 ms 5112 KB Output is correct
7 Correct 6 ms 5112 KB Output is correct
8 Correct 6 ms 4984 KB Output is correct
9 Correct 6 ms 4988 KB Output is correct
10 Correct 6 ms 5112 KB Output is correct
11 Correct 6 ms 5112 KB Output is correct
12 Correct 6 ms 5112 KB Output is correct
13 Correct 6 ms 5112 KB Output is correct
14 Correct 6 ms 5112 KB Output is correct
15 Correct 6 ms 4984 KB Output is correct
16 Correct 6 ms 5112 KB Output is correct
17 Correct 6 ms 5112 KB Output is correct
18 Correct 6 ms 5116 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 5112 KB Output is correct
2 Correct 7 ms 5112 KB Output is correct
3 Correct 8 ms 4984 KB Output is correct
4 Correct 8 ms 5112 KB Output is correct
5 Correct 6 ms 5112 KB Output is correct
6 Correct 6 ms 5112 KB Output is correct
7 Correct 6 ms 5112 KB Output is correct
8 Correct 6 ms 4984 KB Output is correct
9 Correct 6 ms 4988 KB Output is correct
10 Correct 6 ms 5112 KB Output is correct
11 Correct 6 ms 5112 KB Output is correct
12 Correct 6 ms 5112 KB Output is correct
13 Correct 6 ms 5112 KB Output is correct
14 Correct 6 ms 5112 KB Output is correct
15 Correct 6 ms 4984 KB Output is correct
16 Correct 6 ms 5112 KB Output is correct
17 Correct 6 ms 5112 KB Output is correct
18 Correct 6 ms 5116 KB Output is correct
19 Correct 6 ms 5112 KB Output is correct
20 Correct 7 ms 5112 KB Output is correct
21 Correct 7 ms 5112 KB Output is correct
22 Correct 10 ms 8696 KB Output is correct
23 Correct 10 ms 8056 KB Output is correct
24 Correct 10 ms 8440 KB Output is correct
25 Correct 10 ms 8436 KB Output is correct
26 Correct 8 ms 6392 KB Output is correct
27 Correct 9 ms 8184 KB Output is correct
28 Correct 8 ms 5880 KB Output is correct
29 Correct 8 ms 6392 KB Output is correct
30 Correct 10 ms 6520 KB Output is correct
31 Correct 9 ms 7672 KB Output is correct
32 Correct 9 ms 7928 KB Output is correct
33 Correct 10 ms 8184 KB Output is correct
34 Correct 9 ms 7420 KB Output is correct
35 Correct 10 ms 8568 KB Output is correct
36 Correct 10 ms 8696 KB Output is correct
37 Correct 10 ms 8184 KB Output is correct
38 Correct 9 ms 7160 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 5112 KB Output is correct
2 Correct 7 ms 5112 KB Output is correct
3 Correct 8 ms 4984 KB Output is correct
4 Correct 8 ms 5112 KB Output is correct
5 Correct 6 ms 5112 KB Output is correct
6 Correct 6 ms 5112 KB Output is correct
7 Correct 6 ms 5112 KB Output is correct
8 Correct 6 ms 4984 KB Output is correct
9 Correct 6 ms 4988 KB Output is correct
10 Correct 6 ms 5112 KB Output is correct
11 Correct 6 ms 5112 KB Output is correct
12 Correct 6 ms 5112 KB Output is correct
13 Correct 6 ms 5112 KB Output is correct
14 Correct 6 ms 5112 KB Output is correct
15 Correct 6 ms 4984 KB Output is correct
16 Correct 6 ms 5112 KB Output is correct
17 Correct 6 ms 5112 KB Output is correct
18 Correct 6 ms 5116 KB Output is correct
19 Correct 195 ms 11044 KB Output is correct
20 Correct 182 ms 11008 KB Output is correct
21 Correct 188 ms 11140 KB Output is correct
22 Correct 160 ms 11244 KB Output is correct
23 Correct 172 ms 11328 KB Output is correct
24 Correct 104 ms 10876 KB Output is correct
25 Correct 216 ms 15616 KB Output is correct
26 Correct 139 ms 20116 KB Output is correct
27 Correct 267 ms 15844 KB Output is correct
28 Correct 476 ms 35064 KB Output is correct
29 Correct 549 ms 33612 KB Output is correct
30 Correct 271 ms 15736 KB Output is correct
31 Correct 274 ms 15840 KB Output is correct
32 Correct 373 ms 15792 KB Output is correct
33 Correct 523 ms 16352 KB Output is correct
34 Correct 428 ms 16216 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 5112 KB Output is correct
2 Correct 7 ms 5112 KB Output is correct
3 Correct 8 ms 4984 KB Output is correct
4 Correct 8 ms 5112 KB Output is correct
5 Correct 6 ms 5112 KB Output is correct
6 Correct 6 ms 5112 KB Output is correct
7 Correct 6 ms 5112 KB Output is correct
8 Correct 6 ms 4984 KB Output is correct
9 Correct 6 ms 4988 KB Output is correct
10 Correct 6 ms 5112 KB Output is correct
11 Correct 6 ms 5112 KB Output is correct
12 Correct 6 ms 5112 KB Output is correct
13 Correct 6 ms 5112 KB Output is correct
14 Correct 6 ms 5112 KB Output is correct
15 Correct 6 ms 4984 KB Output is correct
16 Correct 6 ms 5112 KB Output is correct
17 Correct 6 ms 5112 KB Output is correct
18 Correct 6 ms 5116 KB Output is correct
19 Correct 6 ms 5112 KB Output is correct
20 Correct 7 ms 5112 KB Output is correct
21 Correct 7 ms 5112 KB Output is correct
22 Correct 10 ms 8696 KB Output is correct
23 Correct 10 ms 8056 KB Output is correct
24 Correct 10 ms 8440 KB Output is correct
25 Correct 10 ms 8436 KB Output is correct
26 Correct 8 ms 6392 KB Output is correct
27 Correct 9 ms 8184 KB Output is correct
28 Correct 8 ms 5880 KB Output is correct
29 Correct 8 ms 6392 KB Output is correct
30 Correct 10 ms 6520 KB Output is correct
31 Correct 9 ms 7672 KB Output is correct
32 Correct 9 ms 7928 KB Output is correct
33 Correct 10 ms 8184 KB Output is correct
34 Correct 9 ms 7420 KB Output is correct
35 Correct 10 ms 8568 KB Output is correct
36 Correct 10 ms 8696 KB Output is correct
37 Correct 10 ms 8184 KB Output is correct
38 Correct 9 ms 7160 KB Output is correct
39 Correct 195 ms 11044 KB Output is correct
40 Correct 182 ms 11008 KB Output is correct
41 Correct 188 ms 11140 KB Output is correct
42 Correct 160 ms 11244 KB Output is correct
43 Correct 172 ms 11328 KB Output is correct
44 Correct 104 ms 10876 KB Output is correct
45 Correct 216 ms 15616 KB Output is correct
46 Correct 139 ms 20116 KB Output is correct
47 Correct 267 ms 15844 KB Output is correct
48 Correct 476 ms 35064 KB Output is correct
49 Correct 549 ms 33612 KB Output is correct
50 Correct 271 ms 15736 KB Output is correct
51 Correct 274 ms 15840 KB Output is correct
52 Correct 373 ms 15792 KB Output is correct
53 Correct 523 ms 16352 KB Output is correct
54 Correct 428 ms 16216 KB Output is correct
55 Correct 19 ms 5752 KB Output is correct
56 Correct 18 ms 5624 KB Output is correct
57 Correct 123 ms 11364 KB Output is correct
58 Correct 50 ms 10476 KB Output is correct
59 Correct 161 ms 21352 KB Output is correct
60 Correct 601 ms 39424 KB Output is correct
61 Correct 272 ms 15864 KB Output is correct
62 Correct 277 ms 19704 KB Output is correct
63 Correct 371 ms 19812 KB Output is correct
64 Correct 577 ms 19044 KB Output is correct
65 Correct 414 ms 17360 KB Output is correct
66 Correct 615 ms 34464 KB Output is correct
67 Correct 158 ms 20068 KB Output is correct
68 Correct 365 ms 21440 KB Output is correct
69 Correct 352 ms 21456 KB Output is correct
70 Correct 329 ms 20940 KB Output is correct