Submission #749897

# Submission time Handle Problem Language Result Execution time Memory
749897 2023-05-28T21:46:53 Z StefanSebez Race (IOI11_race) C++14
100 / 100
1956 ms 48204 KB
#include "race.h"
#include<bits/stdc++.h>
using namespace std;
const int N=2*1e5+50;
const int inf=1e9+50;
vector<pair<int,int> >E[N];
bool bul[N];
int sz[N],parent[N],root,dist[N],depth[N];
int res=inf,k;
map<int,int>mapa;
void DFS(int u)
{
	sz[u]=1;
	for(auto i:E[u])
	{
		if(i.first!=parent[u] && bul[i.first]==false)
		{
			parent[i.first]=u;
			DFS(i.first);
			sz[u]+=sz[i.first];
		}
	}
}
int DFSc(int u)
{
	int ind,maks=0;
	for(auto i:E[u])
	{
		if(i.first!=parent[u] && bul[i.first]==false && sz[i.first]>maks)
		{
			maks=sz[i.first];
			ind=i.first;
		}
	}
	if(maks*2>sz[root])
	{
		return DFSc(ind);
	}
	else
	{
		return u;
	}
}
void DFSdist(int u,int w)
{
	dist[u]=dist[parent[u]]+w;
	depth[u]=depth[parent[u]]+1;
	if(k-dist[u]==0)
	{
		res=min(res,depth[u]);
	}
	else if(k-dist[u]>0 && mapa[k-dist[u]]!=0)
	{
		res=min(res,depth[u]+mapa[k-dist[u]]);
	}
	for(auto i:E[u])
	{
		if(i.first!=parent[u] && bul[i.first]==false)
		{
			DFSdist(i.first,i.second);
		}
	}
}
void DFSadd(int u)
{
	if(mapa[dist[u]]==0)
	{
		mapa[dist[u]]=depth[u];
	}
	else
	{
		mapa[dist[u]]=min(mapa[dist[u]],depth[u]);
	}
	for(auto i:E[u])
	{
        if(i.first!=parent[u] && bul[i.first]==false)
		{
			DFSadd(i.first);
		}
	}
}
void DFSclear(int u)
{
	sz[u]=0;
	dist[u]=0;
	depth[u]=0;
	for(auto i:E[u])
	{
		if(i.first!=parent[u] && bul[i.first]==false)
		{
			DFSclear(i.first);
		}
	}
	parent[u]=-1;
}
void cdecomp(int u)
{
	root=u;
	DFS(u);
	int cent=DFSc(u);
	DFSclear(u);
	/*for(int i=0;i<=N;i++)
	{
		parent[i]=-1;
	}*/
	DFS(cent);
	for(auto i:E[cent])
	{
		if(bul[i.first]==false)
		{
			DFSdist(i.first,i.second);
			DFSadd(i.first);
		}
	}
	DFSclear(cent);
	/*for(int i=0;i<=N;i++)
	{
		parent[i]=-1;
	}*/
	mapa.clear();
	bul[cent]=true;
	for(auto i:E[cent])
	{
		if(bul[i.first]==false)
		{
			cdecomp(i.first);
		}
	}
}
int best_path(int n, int K, int H[][2], int L[])
{
	k=K;
	for(int i=0;i<n-1;i++)
	{
		E[H[i][0]].push_back({H[i][1],L[i]});
		E[H[i][1]].push_back({H[i][0],L[i]});
	}
	for(int i=0;i<=n+50;i++)
	{
		parent[i]=-1;
	}
	cdecomp(0);
	if(res==inf)
	{
		res=-1;
	}
	return res;
}

Compilation message

race.cpp: In function 'int DFSc(int)':
race.cpp:29:23: warning: 'ind' may be used uninitialized in this function [-Wmaybe-uninitialized]
   29 |   if(i.first!=parent[u] && bul[i.first]==false && sz[i.first]>maks)
      |               ~~~~~~~~^
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Correct 3 ms 4948 KB Output is correct
4 Correct 3 ms 4948 KB Output is correct
5 Correct 3 ms 4948 KB Output is correct
6 Correct 3 ms 4948 KB Output is correct
7 Correct 3 ms 4948 KB Output is correct
8 Correct 3 ms 4948 KB Output is correct
9 Correct 3 ms 4948 KB Output is correct
10 Correct 2 ms 4948 KB Output is correct
11 Correct 2 ms 4948 KB Output is correct
12 Correct 3 ms 4948 KB Output is correct
13 Correct 3 ms 4948 KB Output is correct
14 Correct 4 ms 4988 KB Output is correct
15 Correct 3 ms 4948 KB Output is correct
16 Correct 3 ms 4948 KB Output is correct
17 Correct 3 ms 4948 KB Output is correct
18 Correct 4 ms 4948 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Correct 3 ms 4948 KB Output is correct
4 Correct 3 ms 4948 KB Output is correct
5 Correct 3 ms 4948 KB Output is correct
6 Correct 3 ms 4948 KB Output is correct
7 Correct 3 ms 4948 KB Output is correct
8 Correct 3 ms 4948 KB Output is correct
9 Correct 3 ms 4948 KB Output is correct
10 Correct 2 ms 4948 KB Output is correct
11 Correct 2 ms 4948 KB Output is correct
12 Correct 3 ms 4948 KB Output is correct
13 Correct 3 ms 4948 KB Output is correct
14 Correct 4 ms 4988 KB Output is correct
15 Correct 3 ms 4948 KB Output is correct
16 Correct 3 ms 4948 KB Output is correct
17 Correct 3 ms 4948 KB Output is correct
18 Correct 4 ms 4948 KB Output is correct
19 Correct 2 ms 4948 KB Output is correct
20 Correct 3 ms 4948 KB Output is correct
21 Correct 4 ms 5076 KB Output is correct
22 Correct 5 ms 5076 KB Output is correct
23 Correct 5 ms 5076 KB Output is correct
24 Correct 4 ms 5076 KB Output is correct
25 Correct 5 ms 5076 KB Output is correct
26 Correct 5 ms 5076 KB Output is correct
27 Correct 3 ms 5076 KB Output is correct
28 Correct 5 ms 5076 KB Output is correct
29 Correct 5 ms 5076 KB Output is correct
30 Correct 5 ms 5112 KB Output is correct
31 Correct 4 ms 5076 KB Output is correct
32 Correct 5 ms 5204 KB Output is correct
33 Correct 6 ms 5148 KB Output is correct
34 Correct 4 ms 5076 KB Output is correct
35 Correct 4 ms 5076 KB Output is correct
36 Correct 5 ms 5076 KB Output is correct
37 Correct 5 ms 5076 KB Output is correct
38 Correct 5 ms 5192 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Correct 3 ms 4948 KB Output is correct
4 Correct 3 ms 4948 KB Output is correct
5 Correct 3 ms 4948 KB Output is correct
6 Correct 3 ms 4948 KB Output is correct
7 Correct 3 ms 4948 KB Output is correct
8 Correct 3 ms 4948 KB Output is correct
9 Correct 3 ms 4948 KB Output is correct
10 Correct 2 ms 4948 KB Output is correct
11 Correct 2 ms 4948 KB Output is correct
12 Correct 3 ms 4948 KB Output is correct
13 Correct 3 ms 4948 KB Output is correct
14 Correct 4 ms 4988 KB Output is correct
15 Correct 3 ms 4948 KB Output is correct
16 Correct 3 ms 4948 KB Output is correct
17 Correct 3 ms 4948 KB Output is correct
18 Correct 4 ms 4948 KB Output is correct
19 Correct 416 ms 11552 KB Output is correct
20 Correct 375 ms 11528 KB Output is correct
21 Correct 344 ms 11544 KB Output is correct
22 Correct 297 ms 11600 KB Output is correct
23 Correct 377 ms 11820 KB Output is correct
24 Correct 165 ms 11576 KB Output is correct
25 Correct 308 ms 15192 KB Output is correct
26 Correct 148 ms 17196 KB Output is correct
27 Correct 380 ms 18336 KB Output is correct
28 Correct 1314 ms 41876 KB Output is correct
29 Correct 1285 ms 40876 KB Output is correct
30 Correct 388 ms 21300 KB Output is correct
31 Correct 386 ms 21324 KB Output is correct
32 Correct 537 ms 21304 KB Output is correct
33 Correct 830 ms 20024 KB Output is correct
34 Correct 1128 ms 30284 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Correct 3 ms 4948 KB Output is correct
4 Correct 3 ms 4948 KB Output is correct
5 Correct 3 ms 4948 KB Output is correct
6 Correct 3 ms 4948 KB Output is correct
7 Correct 3 ms 4948 KB Output is correct
8 Correct 3 ms 4948 KB Output is correct
9 Correct 3 ms 4948 KB Output is correct
10 Correct 2 ms 4948 KB Output is correct
11 Correct 2 ms 4948 KB Output is correct
12 Correct 3 ms 4948 KB Output is correct
13 Correct 3 ms 4948 KB Output is correct
14 Correct 4 ms 4988 KB Output is correct
15 Correct 3 ms 4948 KB Output is correct
16 Correct 3 ms 4948 KB Output is correct
17 Correct 3 ms 4948 KB Output is correct
18 Correct 4 ms 4948 KB Output is correct
19 Correct 2 ms 4948 KB Output is correct
20 Correct 3 ms 4948 KB Output is correct
21 Correct 4 ms 5076 KB Output is correct
22 Correct 5 ms 5076 KB Output is correct
23 Correct 5 ms 5076 KB Output is correct
24 Correct 4 ms 5076 KB Output is correct
25 Correct 5 ms 5076 KB Output is correct
26 Correct 5 ms 5076 KB Output is correct
27 Correct 3 ms 5076 KB Output is correct
28 Correct 5 ms 5076 KB Output is correct
29 Correct 5 ms 5076 KB Output is correct
30 Correct 5 ms 5112 KB Output is correct
31 Correct 4 ms 5076 KB Output is correct
32 Correct 5 ms 5204 KB Output is correct
33 Correct 6 ms 5148 KB Output is correct
34 Correct 4 ms 5076 KB Output is correct
35 Correct 4 ms 5076 KB Output is correct
36 Correct 5 ms 5076 KB Output is correct
37 Correct 5 ms 5076 KB Output is correct
38 Correct 5 ms 5192 KB Output is correct
39 Correct 416 ms 11552 KB Output is correct
40 Correct 375 ms 11528 KB Output is correct
41 Correct 344 ms 11544 KB Output is correct
42 Correct 297 ms 11600 KB Output is correct
43 Correct 377 ms 11820 KB Output is correct
44 Correct 165 ms 11576 KB Output is correct
45 Correct 308 ms 15192 KB Output is correct
46 Correct 148 ms 17196 KB Output is correct
47 Correct 380 ms 18336 KB Output is correct
48 Correct 1314 ms 41876 KB Output is correct
49 Correct 1285 ms 40876 KB Output is correct
50 Correct 388 ms 21300 KB Output is correct
51 Correct 386 ms 21324 KB Output is correct
52 Correct 537 ms 21304 KB Output is correct
53 Correct 830 ms 20024 KB Output is correct
54 Correct 1128 ms 30284 KB Output is correct
55 Correct 33 ms 6168 KB Output is correct
56 Correct 24 ms 5792 KB Output is correct
57 Correct 244 ms 13068 KB Output is correct
58 Correct 46 ms 12744 KB Output is correct
59 Correct 441 ms 25468 KB Output is correct
60 Correct 1719 ms 48204 KB Output is correct
61 Correct 474 ms 22604 KB Output is correct
62 Correct 433 ms 21580 KB Output is correct
63 Correct 581 ms 21540 KB Output is correct
64 Correct 1956 ms 30740 KB Output is correct
65 Correct 1158 ms 31340 KB Output is correct
66 Correct 1568 ms 39252 KB Output is correct
67 Correct 152 ms 21980 KB Output is correct
68 Correct 815 ms 33636 KB Output is correct
69 Correct 784 ms 33484 KB Output is correct
70 Correct 732 ms 32200 KB Output is correct