Submission #332592

# Submission time Handle Problem Language Result Execution time Memory
332592 2020-12-02T22:34:56 Z MilosMilutinovic Race (IOI11_race) C++14
100 / 100
578 ms 39256 KB
#include "race.h"
#include <stdio.h>
#include <vector>
using namespace std;
#define ll long int
#define pb push_back
#define mp make_pair
const int N=200050;
const int M=1000050;
const int inf=1e9;
int min(int a, int b){ return a>b?b:a;}
vector<pair<int,int> > E[N];
void AddEdge(int u, int v, int w){ E[u].pb(mp(v,w));E[v].pb(mp(u,w));}
int k;
int sz[N];
bool vis[N];
void DFS(int u, int p, int &n)
{
	n++;sz[u]=1;
	for(int i=0;i<E[u].size();i++)
	{
		int v=E[u][i].first;
		if(v!=p && !vis[v]) DFS(v,u,n),sz[u]+=sz[v];
	}
}
int Find(int u, int p, int n)
{
	for(int i=0;i<E[u].size();i++)
	{
		int v=E[u][i].first;
		if(v!=p && !vis[v] && sz[v]>n/2) return Find(v,u,n);
	}
	return u;
}
int Find(int u){ int n=0;DFS(u,u,n);return Find(u,u,n);}
vector<pair<int,int> > bck,lzy;
int Min[M],ans=inf;
void Solve(int u, int p, int d, int w)
{
	if(w>k) return;
	bck.pb(mp(w,d));
	lzy.pb(mp(w,d));
	ans=min(ans,Min[k-w]+d);
	for(int i=0;i<E[u].size();i++)
	{
		int v=E[u][i].first;
		int add=E[u][i].second;
		if(v!=p && !vis[v]) Solve(v,u,d+1,w+add);
	}
}
void Decompose(int u)
{
	u=Find(u);vis[u]=1;
	int i,j;
	Min[0]=0;
	lzy.pb(mp(0,0));
	for(i=0;i<E[u].size();i++)
	{
		int v=E[u][i].first;
		int w=E[u][i].second;
		if(!vis[v])
		{
			Solve(v,u,1,w);
			for(j=0;j<bck.size();j++) Min[bck[j].first]=min(Min[bck[j].first],bck[j].second);
			bck.clear();
		}
	}
	for(i=0;i<lzy.size();i++) Min[lzy[i].first]=inf;
	lzy.clear();
	for(i=0;i<E[u].size();i++)
	{
		int v=E[u][i].first;
		if(!vis[v]) Decompose(v);
	}
}
int best_path(int N, int K, int H[][2], int L[])
{
	int i;k=K;int n=N;
	for(i=0;i<n-1;i++) AddEdge(H[i][0]+1,H[i][1]+1,L[i]);
	for(i=0;i<=k;i++) Min[i]=inf;
	Decompose(1);
	if(ans==inf) return -1;
	return ans;
}

Compilation message

race.cpp: In function 'void DFS(int, int, int&)':
race.cpp:20:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   20 |  for(int i=0;i<E[u].size();i++)
      |              ~^~~~~~~~~~~~
race.cpp: In function 'int Find(int, int, int)':
race.cpp:28:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   28 |  for(int i=0;i<E[u].size();i++)
      |              ~^~~~~~~~~~~~
race.cpp: In function 'void Solve(int, int, int, int)':
race.cpp:44:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   44 |  for(int i=0;i<E[u].size();i++)
      |              ~^~~~~~~~~~~~
race.cpp: In function 'void Decompose(int)':
race.cpp:57:11: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   57 |  for(i=0;i<E[u].size();i++)
      |          ~^~~~~~~~~~~~
race.cpp:64:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   64 |    for(j=0;j<bck.size();j++) Min[bck[j].first]=min(Min[bck[j].first],bck[j].second);
      |            ~^~~~~~~~~~~
race.cpp:68:11: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   68 |  for(i=0;i<lzy.size();i++) Min[lzy[i].first]=inf;
      |          ~^~~~~~~~~~~
race.cpp:70:11: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   70 |  for(i=0;i<E[u].size();i++)
      |          ~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 3 ms 5100 KB Output is correct
2 Correct 3 ms 5100 KB Output is correct
3 Correct 3 ms 5100 KB Output is correct
4 Correct 3 ms 5100 KB Output is correct
5 Correct 3 ms 5100 KB Output is correct
6 Correct 4 ms 5100 KB Output is correct
7 Correct 3 ms 5100 KB Output is correct
8 Correct 3 ms 5100 KB Output is correct
9 Correct 3 ms 5100 KB Output is correct
10 Correct 3 ms 5100 KB Output is correct
11 Correct 3 ms 5100 KB Output is correct
12 Correct 3 ms 5100 KB Output is correct
13 Correct 3 ms 5100 KB Output is correct
14 Correct 3 ms 5100 KB Output is correct
15 Correct 4 ms 5100 KB Output is correct
16 Correct 4 ms 5100 KB Output is correct
17 Correct 4 ms 5100 KB Output is correct
18 Correct 4 ms 5100 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 5100 KB Output is correct
2 Correct 3 ms 5100 KB Output is correct
3 Correct 3 ms 5100 KB Output is correct
4 Correct 3 ms 5100 KB Output is correct
5 Correct 3 ms 5100 KB Output is correct
6 Correct 4 ms 5100 KB Output is correct
7 Correct 3 ms 5100 KB Output is correct
8 Correct 3 ms 5100 KB Output is correct
9 Correct 3 ms 5100 KB Output is correct
10 Correct 3 ms 5100 KB Output is correct
11 Correct 3 ms 5100 KB Output is correct
12 Correct 3 ms 5100 KB Output is correct
13 Correct 3 ms 5100 KB Output is correct
14 Correct 3 ms 5100 KB Output is correct
15 Correct 4 ms 5100 KB Output is correct
16 Correct 4 ms 5100 KB Output is correct
17 Correct 4 ms 5100 KB Output is correct
18 Correct 4 ms 5100 KB Output is correct
19 Correct 4 ms 5100 KB Output is correct
20 Correct 4 ms 5100 KB Output is correct
21 Correct 4 ms 5100 KB Output is correct
22 Correct 7 ms 8812 KB Output is correct
23 Correct 6 ms 8044 KB Output is correct
24 Correct 8 ms 8428 KB Output is correct
25 Correct 7 ms 8428 KB Output is correct
26 Correct 5 ms 6380 KB Output is correct
27 Correct 10 ms 8172 KB Output is correct
28 Correct 5 ms 5868 KB Output is correct
29 Correct 5 ms 6380 KB Output is correct
30 Correct 5 ms 6508 KB Output is correct
31 Correct 6 ms 7660 KB Output is correct
32 Correct 6 ms 7916 KB Output is correct
33 Correct 7 ms 8172 KB Output is correct
34 Correct 6 ms 7404 KB Output is correct
35 Correct 6 ms 8300 KB Output is correct
36 Correct 7 ms 8832 KB Output is correct
37 Correct 6 ms 8172 KB Output is correct
38 Correct 6 ms 7148 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 5100 KB Output is correct
2 Correct 3 ms 5100 KB Output is correct
3 Correct 3 ms 5100 KB Output is correct
4 Correct 3 ms 5100 KB Output is correct
5 Correct 3 ms 5100 KB Output is correct
6 Correct 4 ms 5100 KB Output is correct
7 Correct 3 ms 5100 KB Output is correct
8 Correct 3 ms 5100 KB Output is correct
9 Correct 3 ms 5100 KB Output is correct
10 Correct 3 ms 5100 KB Output is correct
11 Correct 3 ms 5100 KB Output is correct
12 Correct 3 ms 5100 KB Output is correct
13 Correct 3 ms 5100 KB Output is correct
14 Correct 3 ms 5100 KB Output is correct
15 Correct 4 ms 5100 KB Output is correct
16 Correct 4 ms 5100 KB Output is correct
17 Correct 4 ms 5100 KB Output is correct
18 Correct 4 ms 5100 KB Output is correct
19 Correct 152 ms 12044 KB Output is correct
20 Correct 151 ms 11884 KB Output is correct
21 Correct 168 ms 12520 KB Output is correct
22 Correct 175 ms 13284 KB Output is correct
23 Correct 98 ms 12140 KB Output is correct
24 Correct 70 ms 12012 KB Output is correct
25 Correct 139 ms 15340 KB Output is correct
26 Correct 125 ms 20576 KB Output is correct
27 Correct 208 ms 19052 KB Output is correct
28 Correct 313 ms 33260 KB Output is correct
29 Correct 313 ms 32236 KB Output is correct
30 Correct 205 ms 18924 KB Output is correct
31 Correct 210 ms 19052 KB Output is correct
32 Correct 258 ms 19180 KB Output is correct
33 Correct 266 ms 17772 KB Output is correct
34 Correct 230 ms 18668 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 5100 KB Output is correct
2 Correct 3 ms 5100 KB Output is correct
3 Correct 3 ms 5100 KB Output is correct
4 Correct 3 ms 5100 KB Output is correct
5 Correct 3 ms 5100 KB Output is correct
6 Correct 4 ms 5100 KB Output is correct
7 Correct 3 ms 5100 KB Output is correct
8 Correct 3 ms 5100 KB Output is correct
9 Correct 3 ms 5100 KB Output is correct
10 Correct 3 ms 5100 KB Output is correct
11 Correct 3 ms 5100 KB Output is correct
12 Correct 3 ms 5100 KB Output is correct
13 Correct 3 ms 5100 KB Output is correct
14 Correct 3 ms 5100 KB Output is correct
15 Correct 4 ms 5100 KB Output is correct
16 Correct 4 ms 5100 KB Output is correct
17 Correct 4 ms 5100 KB Output is correct
18 Correct 4 ms 5100 KB Output is correct
19 Correct 4 ms 5100 KB Output is correct
20 Correct 4 ms 5100 KB Output is correct
21 Correct 4 ms 5100 KB Output is correct
22 Correct 7 ms 8812 KB Output is correct
23 Correct 6 ms 8044 KB Output is correct
24 Correct 8 ms 8428 KB Output is correct
25 Correct 7 ms 8428 KB Output is correct
26 Correct 5 ms 6380 KB Output is correct
27 Correct 10 ms 8172 KB Output is correct
28 Correct 5 ms 5868 KB Output is correct
29 Correct 5 ms 6380 KB Output is correct
30 Correct 5 ms 6508 KB Output is correct
31 Correct 6 ms 7660 KB Output is correct
32 Correct 6 ms 7916 KB Output is correct
33 Correct 7 ms 8172 KB Output is correct
34 Correct 6 ms 7404 KB Output is correct
35 Correct 6 ms 8300 KB Output is correct
36 Correct 7 ms 8832 KB Output is correct
37 Correct 6 ms 8172 KB Output is correct
38 Correct 6 ms 7148 KB Output is correct
39 Correct 152 ms 12044 KB Output is correct
40 Correct 151 ms 11884 KB Output is correct
41 Correct 168 ms 12520 KB Output is correct
42 Correct 175 ms 13284 KB Output is correct
43 Correct 98 ms 12140 KB Output is correct
44 Correct 70 ms 12012 KB Output is correct
45 Correct 139 ms 15340 KB Output is correct
46 Correct 125 ms 20576 KB Output is correct
47 Correct 208 ms 19052 KB Output is correct
48 Correct 313 ms 33260 KB Output is correct
49 Correct 313 ms 32236 KB Output is correct
50 Correct 205 ms 18924 KB Output is correct
51 Correct 210 ms 19052 KB Output is correct
52 Correct 258 ms 19180 KB Output is correct
53 Correct 266 ms 17772 KB Output is correct
54 Correct 230 ms 18668 KB Output is correct
55 Correct 12 ms 5868 KB Output is correct
56 Correct 13 ms 5996 KB Output is correct
57 Correct 107 ms 13408 KB Output is correct
58 Correct 48 ms 13152 KB Output is correct
59 Correct 124 ms 21216 KB Output is correct
60 Correct 507 ms 39256 KB Output is correct
61 Correct 229 ms 19560 KB Output is correct
62 Correct 263 ms 24808 KB Output is correct
63 Correct 339 ms 24892 KB Output is correct
64 Correct 578 ms 23944 KB Output is correct
65 Correct 294 ms 19692 KB Output is correct
66 Correct 466 ms 34028 KB Output is correct
67 Correct 155 ms 26332 KB Output is correct
68 Correct 357 ms 24548 KB Output is correct
69 Correct 326 ms 24700 KB Output is correct
70 Correct 325 ms 23908 KB Output is correct