Submission #67305

# Submission time Handle Problem Language Result Execution time Memory
67305 2018-08-13T21:30:52 Z zetapi Race (IOI11_race) C++14
21 / 100
3000 ms 33112 KB
#include <bits/stdc++.h>
using namespace std;

#define pb  push_back
#define mp  make_pair
#define ll  long long
#define itr ::iterator 

const int MAX=3e5;
const ll  INF=1e9;

typedef pair<ll,ll> pii;

map<ll,ll> maps;

vector<pii> later,vec[MAX];

ll K,res,height[MAX],SubSize[MAX],Special[MAX],Weight[MAX];

void Prepare(int node,int par,int hei)
{
	SubSize[node]=1;
	height[node]=hei;
	for(auto A:vec[node])
	{
		if(A.first==par)
			continue;
		Weight[A.first]=Weight[node]+A.second;
		Prepare(A.first,node,hei+1);
		SubSize[node]+=SubSize[A.first];
	}
	pii cur=mp(-1,-1);
	for(auto A:vec[node])
	{
		if(A.first==par)
			continue;
		cur=max(cur,mp(SubSize[A.first],A.first));
	}
	Special[node]=cur.second;
	return ;
}

void relax(ll x,ll y)
{
	if(maps.count(x))
		maps[x]=min(maps[x],y);
	else
		maps[x]=y;
}

void cal(int node,int par,int CurrentRoot)
{
	later.pb(mp(Weight[node],height[node]));
	if(maps.count(K+2*Weight[CurrentRoot]-Weight[node]))
	{
		//cout<<CurrentRoot<<" "<<node<<" "<<Weight[CurrentRoot]<<" "<<Weight[node]<<" required more "<<K+2*Weight[CurrentRoot]-Weight[node]<<"\n";
		res=min(res,height[node]-height[CurrentRoot]+maps[K+2*Weight[CurrentRoot]-Weight[node]]-height[CurrentRoot]);
	}
	if(Weight[node]-Weight[CurrentRoot]==K)
		res=min(res,height[node]-height[CurrentRoot]);
	for(auto A:vec[node])
	{
		if(A.first==par)
			continue;
		cal(A.first,node,CurrentRoot);
	}
	return ;
}

void dfs(int node,int par)		
{
	for(auto A:vec[node])
	{
		if(A.first==par)
			continue;
		dfs(A.first,node);
	}
	//relax(Weight[node],height[node]);
	for(auto A:vec[node])
	{
		if(A.first==par)
			continue;
		cal(A.first,node,node);	
		for(auto A:later)
			relax(A.first,A.second);
		later.clear();
	}
	maps.clear();
	return ;
}

int best_path(int N,int K_,int H[][2],int L[])
{
	K=K_;
 	for(int A=0;A<N-1;A++)
 	{
 		vec[H[A][0]].pb(mp(H[A][1],L[A]));
 		vec[H[A][1]].pb(mp(H[A][0],L[A]));
 	}
 	res=INF;
 	Prepare(0,-1,0);
 	dfs(0,-1);
 	if(res==INF)
 		res=-1;
 	return res;
}

/*int main()
{
	ios_base::sync_with_stdio(false);

	
	int N=11,K=12;
	int 		   L[]={3,
					    4,
					    5,
					    4,
						6,
						3,
						2,
						5,
						6,
						7};
	int H[][2]={{0,1},
				{0,2},
				{2,3},
				{3,4},
				{4,5},
				{0,6},
				{6,7},
				{6,8},
				{8,9},
				{8,10}};

	//N=4,K=3;
	//int H[][2]={{0,1},{1,2},{1,3}},L[]={1,2,4};
	cout<<best_path(N,K,H,L);
	return 0;
}*/
# Verdict Execution time Memory Grader output
1 Correct 9 ms 7416 KB Output is correct
2 Correct 10 ms 7416 KB Output is correct
3 Correct 9 ms 7576 KB Output is correct
4 Correct 10 ms 7576 KB Output is correct
5 Correct 11 ms 7576 KB Output is correct
6 Correct 9 ms 7660 KB Output is correct
7 Correct 11 ms 7712 KB Output is correct
8 Correct 11 ms 7712 KB Output is correct
9 Correct 9 ms 7832 KB Output is correct
10 Correct 10 ms 7832 KB Output is correct
11 Correct 9 ms 7832 KB Output is correct
12 Correct 8 ms 7832 KB Output is correct
13 Correct 9 ms 7832 KB Output is correct
14 Correct 8 ms 7832 KB Output is correct
15 Correct 9 ms 7832 KB Output is correct
16 Correct 8 ms 7832 KB Output is correct
17 Correct 9 ms 7832 KB Output is correct
18 Correct 9 ms 7864 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 7416 KB Output is correct
2 Correct 10 ms 7416 KB Output is correct
3 Correct 9 ms 7576 KB Output is correct
4 Correct 10 ms 7576 KB Output is correct
5 Correct 11 ms 7576 KB Output is correct
6 Correct 9 ms 7660 KB Output is correct
7 Correct 11 ms 7712 KB Output is correct
8 Correct 11 ms 7712 KB Output is correct
9 Correct 9 ms 7832 KB Output is correct
10 Correct 10 ms 7832 KB Output is correct
11 Correct 9 ms 7832 KB Output is correct
12 Correct 8 ms 7832 KB Output is correct
13 Correct 9 ms 7832 KB Output is correct
14 Correct 8 ms 7832 KB Output is correct
15 Correct 9 ms 7832 KB Output is correct
16 Correct 8 ms 7832 KB Output is correct
17 Correct 9 ms 7832 KB Output is correct
18 Correct 9 ms 7864 KB Output is correct
19 Correct 8 ms 7864 KB Output is correct
20 Correct 8 ms 7864 KB Output is correct
21 Correct 11 ms 7936 KB Output is correct
22 Correct 12 ms 7948 KB Output is correct
23 Correct 18 ms 8092 KB Output is correct
24 Correct 11 ms 8092 KB Output is correct
25 Correct 10 ms 8092 KB Output is correct
26 Correct 11 ms 8096 KB Output is correct
27 Correct 8 ms 8096 KB Output is correct
28 Correct 11 ms 8168 KB Output is correct
29 Correct 10 ms 8184 KB Output is correct
30 Correct 11 ms 8184 KB Output is correct
31 Correct 10 ms 8184 KB Output is correct
32 Correct 11 ms 8184 KB Output is correct
33 Correct 12 ms 8184 KB Output is correct
34 Correct 30 ms 8192 KB Output is correct
35 Correct 33 ms 8208 KB Output is correct
36 Correct 35 ms 8220 KB Output is correct
37 Correct 21 ms 8332 KB Output is correct
38 Correct 18 ms 8332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 7416 KB Output is correct
2 Correct 10 ms 7416 KB Output is correct
3 Correct 9 ms 7576 KB Output is correct
4 Correct 10 ms 7576 KB Output is correct
5 Correct 11 ms 7576 KB Output is correct
6 Correct 9 ms 7660 KB Output is correct
7 Correct 11 ms 7712 KB Output is correct
8 Correct 11 ms 7712 KB Output is correct
9 Correct 9 ms 7832 KB Output is correct
10 Correct 10 ms 7832 KB Output is correct
11 Correct 9 ms 7832 KB Output is correct
12 Correct 8 ms 7832 KB Output is correct
13 Correct 9 ms 7832 KB Output is correct
14 Correct 8 ms 7832 KB Output is correct
15 Correct 9 ms 7832 KB Output is correct
16 Correct 8 ms 7832 KB Output is correct
17 Correct 9 ms 7832 KB Output is correct
18 Correct 9 ms 7864 KB Output is correct
19 Correct 799 ms 21152 KB Output is correct
20 Correct 843 ms 22476 KB Output is correct
21 Correct 524 ms 23928 KB Output is correct
22 Correct 532 ms 25220 KB Output is correct
23 Correct 891 ms 27044 KB Output is correct
24 Correct 393 ms 27732 KB Output is correct
25 Execution timed out 3056 ms 33112 KB Time limit exceeded
26 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 9 ms 7416 KB Output is correct
2 Correct 10 ms 7416 KB Output is correct
3 Correct 9 ms 7576 KB Output is correct
4 Correct 10 ms 7576 KB Output is correct
5 Correct 11 ms 7576 KB Output is correct
6 Correct 9 ms 7660 KB Output is correct
7 Correct 11 ms 7712 KB Output is correct
8 Correct 11 ms 7712 KB Output is correct
9 Correct 9 ms 7832 KB Output is correct
10 Correct 10 ms 7832 KB Output is correct
11 Correct 9 ms 7832 KB Output is correct
12 Correct 8 ms 7832 KB Output is correct
13 Correct 9 ms 7832 KB Output is correct
14 Correct 8 ms 7832 KB Output is correct
15 Correct 9 ms 7832 KB Output is correct
16 Correct 8 ms 7832 KB Output is correct
17 Correct 9 ms 7832 KB Output is correct
18 Correct 9 ms 7864 KB Output is correct
19 Correct 8 ms 7864 KB Output is correct
20 Correct 8 ms 7864 KB Output is correct
21 Correct 11 ms 7936 KB Output is correct
22 Correct 12 ms 7948 KB Output is correct
23 Correct 18 ms 8092 KB Output is correct
24 Correct 11 ms 8092 KB Output is correct
25 Correct 10 ms 8092 KB Output is correct
26 Correct 11 ms 8096 KB Output is correct
27 Correct 8 ms 8096 KB Output is correct
28 Correct 11 ms 8168 KB Output is correct
29 Correct 10 ms 8184 KB Output is correct
30 Correct 11 ms 8184 KB Output is correct
31 Correct 10 ms 8184 KB Output is correct
32 Correct 11 ms 8184 KB Output is correct
33 Correct 12 ms 8184 KB Output is correct
34 Correct 30 ms 8192 KB Output is correct
35 Correct 33 ms 8208 KB Output is correct
36 Correct 35 ms 8220 KB Output is correct
37 Correct 21 ms 8332 KB Output is correct
38 Correct 18 ms 8332 KB Output is correct
39 Correct 799 ms 21152 KB Output is correct
40 Correct 843 ms 22476 KB Output is correct
41 Correct 524 ms 23928 KB Output is correct
42 Correct 532 ms 25220 KB Output is correct
43 Correct 891 ms 27044 KB Output is correct
44 Correct 393 ms 27732 KB Output is correct
45 Execution timed out 3056 ms 33112 KB Time limit exceeded
46 Halted 0 ms 0 KB -