Submission #331509

# Submission time Handle Problem Language Result Execution time Memory
331509 2020-11-28T18:07:11 Z SavicS Race (IOI11_race) C++14
100 / 100
888 ms 43832 KB
#include "race.h"
#include <bits/stdc++.h>
using namespace std;
vector<int> g[200007], w[200007];
bool vi[200007];
int x,c,p[200007],b[1000007],sol,k;
queue<pair<int,int> > q;
queue<int> qb;
//isto
void dfsbroj(int s,int f)
{
	if(vi[s]) return;
	x++;
	for(int i=0;i<g[s].size();i++) if(g[s][i]!=f) dfsbroj(g[s][i],s);
}

//isto
int dfs(int s,int f)
{
	if(vi[s]) return 0;
	int k=1;
	bool moze=true;
	for(int i=0;i<g[s].size();i++) if(g[s][i]!=f)
	{
	    int a=dfs(g[s][i],s);
        if(a>x/2) moze=false;
	    k+=a;
	}
	if(x-k>x/2) moze=false;
	if(moze) c=s;
	return k;
}

void dfssolve(int s,int f,int d,int dist)
{
	if(vi[s] || dist>k) return;
	q.push(make_pair(d,dist));
	qb.push(dist);
	for(int i=0;i<g[s].size();i++) if(g[s][i]!=f) dfssolve(g[s][i],s,d+1,dist+w[s][i]);
}

void centrodecomp(int s,int f)
{
	x=0;
	dfsbroj(s,f);
	dfs(s,f);
	vi[c]=true;
	for(int i=0;i<g[c].size();i++) if(!vi[g[c][i]])
	{
	    dfssolve(g[c][i],c,1,w[c][i]);
	    queue<pair<int,int> > qv;
	    while(!q.empty())
	    {
	    	sol=fmin(sol,q.front().first+b[k-q.front().second]);
	    	qv.push(q.front());
	    	q.pop();
		}
		while(!qv.empty())
		{
			b[qv.front().second]=fmin(b[qv.front().second],qv.front().first);
			qv.pop();
		}
	}
	while(!qb.empty())
	{
		b[qb.front()]=100000007;
		qb.pop();
	}
	int r=c;
	for(int i=0;i<g[r].size();i++) if(!vi[g[r][i]]) centrodecomp(g[r][i],r);
}
int best_path(int N, int K, int H[][2], int L[])
{
	k=K;
	for(int i=0;i<N-1;i++)
	{
		g[H[i][0]].push_back(H[i][1]);
		w[H[i][0]].push_back(L[i]);
		g[H[i][1]].push_back(H[i][0]);
		w[H[i][1]].push_back(L[i]);
	}
	sol=100000007;
	for(int i=1;i<1000007;i++) b[i]=100000007;
	centrodecomp(0,-2);
	return (sol>N?-1:sol);
}

Compilation message

race.cpp: In function 'void dfsbroj(int, int)':
race.cpp:14:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   14 |  for(int i=0;i<g[s].size();i++) if(g[s][i]!=f) dfsbroj(g[s][i],s);
      |              ~^~~~~~~~~~~~
race.cpp: In function 'int dfs(int, int)':
race.cpp:23:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   23 |  for(int i=0;i<g[s].size();i++) if(g[s][i]!=f)
      |              ~^~~~~~~~~~~~
race.cpp: In function 'void dfssolve(int, int, int, int)':
race.cpp:39:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   39 |  for(int i=0;i<g[s].size();i++) if(g[s][i]!=f) dfssolve(g[s][i],s,d+1,dist+w[s][i]);
      |              ~^~~~~~~~~~~~
race.cpp: In function 'void centrodecomp(int, int)':
race.cpp:48:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   48 |  for(int i=0;i<g[c].size();i++) if(!vi[g[c][i]])
      |              ~^~~~~~~~~~~~
race.cpp:70:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   70 |  for(int i=0;i<g[r].size();i++) if(!vi[g[r][i]]) centrodecomp(g[r][i],r);
      |              ~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 9 ms 13676 KB Output is correct
2 Correct 10 ms 13676 KB Output is correct
3 Correct 9 ms 13676 KB Output is correct
4 Correct 10 ms 13676 KB Output is correct
5 Correct 9 ms 13676 KB Output is correct
6 Correct 9 ms 13676 KB Output is correct
7 Correct 9 ms 13676 KB Output is correct
8 Correct 9 ms 13676 KB Output is correct
9 Correct 9 ms 13676 KB Output is correct
10 Correct 9 ms 13676 KB Output is correct
11 Correct 10 ms 13804 KB Output is correct
12 Correct 10 ms 13676 KB Output is correct
13 Correct 10 ms 13676 KB Output is correct
14 Correct 9 ms 13676 KB Output is correct
15 Correct 10 ms 13676 KB Output is correct
16 Correct 9 ms 13676 KB Output is correct
17 Correct 10 ms 13676 KB Output is correct
18 Correct 10 ms 13676 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 13676 KB Output is correct
2 Correct 10 ms 13676 KB Output is correct
3 Correct 9 ms 13676 KB Output is correct
4 Correct 10 ms 13676 KB Output is correct
5 Correct 9 ms 13676 KB Output is correct
6 Correct 9 ms 13676 KB Output is correct
7 Correct 9 ms 13676 KB Output is correct
8 Correct 9 ms 13676 KB Output is correct
9 Correct 9 ms 13676 KB Output is correct
10 Correct 9 ms 13676 KB Output is correct
11 Correct 10 ms 13804 KB Output is correct
12 Correct 10 ms 13676 KB Output is correct
13 Correct 10 ms 13676 KB Output is correct
14 Correct 9 ms 13676 KB Output is correct
15 Correct 10 ms 13676 KB Output is correct
16 Correct 9 ms 13676 KB Output is correct
17 Correct 10 ms 13676 KB Output is correct
18 Correct 10 ms 13676 KB Output is correct
19 Correct 10 ms 13676 KB Output is correct
20 Correct 9 ms 13676 KB Output is correct
21 Correct 11 ms 13804 KB Output is correct
22 Correct 11 ms 13804 KB Output is correct
23 Correct 10 ms 13676 KB Output is correct
24 Correct 11 ms 13804 KB Output is correct
25 Correct 11 ms 13804 KB Output is correct
26 Correct 10 ms 13804 KB Output is correct
27 Correct 11 ms 13804 KB Output is correct
28 Correct 10 ms 13804 KB Output is correct
29 Correct 11 ms 13804 KB Output is correct
30 Correct 11 ms 13824 KB Output is correct
31 Correct 11 ms 13804 KB Output is correct
32 Correct 10 ms 13804 KB Output is correct
33 Correct 11 ms 13804 KB Output is correct
34 Correct 11 ms 13804 KB Output is correct
35 Correct 11 ms 13804 KB Output is correct
36 Correct 12 ms 13804 KB Output is correct
37 Correct 10 ms 13804 KB Output is correct
38 Correct 10 ms 13676 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 13676 KB Output is correct
2 Correct 10 ms 13676 KB Output is correct
3 Correct 9 ms 13676 KB Output is correct
4 Correct 10 ms 13676 KB Output is correct
5 Correct 9 ms 13676 KB Output is correct
6 Correct 9 ms 13676 KB Output is correct
7 Correct 9 ms 13676 KB Output is correct
8 Correct 9 ms 13676 KB Output is correct
9 Correct 9 ms 13676 KB Output is correct
10 Correct 9 ms 13676 KB Output is correct
11 Correct 10 ms 13804 KB Output is correct
12 Correct 10 ms 13676 KB Output is correct
13 Correct 10 ms 13676 KB Output is correct
14 Correct 9 ms 13676 KB Output is correct
15 Correct 10 ms 13676 KB Output is correct
16 Correct 9 ms 13676 KB Output is correct
17 Correct 10 ms 13676 KB Output is correct
18 Correct 10 ms 13676 KB Output is correct
19 Correct 265 ms 21484 KB Output is correct
20 Correct 242 ms 21376 KB Output is correct
21 Correct 265 ms 21612 KB Output is correct
22 Correct 266 ms 21888 KB Output is correct
23 Correct 172 ms 21228 KB Output is correct
24 Correct 116 ms 21612 KB Output is correct
25 Correct 214 ms 24556 KB Output is correct
26 Correct 159 ms 28268 KB Output is correct
27 Correct 344 ms 30060 KB Output is correct
28 Correct 490 ms 41196 KB Output is correct
29 Correct 481 ms 41708 KB Output is correct
30 Correct 344 ms 31468 KB Output is correct
31 Correct 350 ms 31468 KB Output is correct
32 Correct 423 ms 31596 KB Output is correct
33 Correct 419 ms 30444 KB Output is correct
34 Correct 370 ms 30316 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 13676 KB Output is correct
2 Correct 10 ms 13676 KB Output is correct
3 Correct 9 ms 13676 KB Output is correct
4 Correct 10 ms 13676 KB Output is correct
5 Correct 9 ms 13676 KB Output is correct
6 Correct 9 ms 13676 KB Output is correct
7 Correct 9 ms 13676 KB Output is correct
8 Correct 9 ms 13676 KB Output is correct
9 Correct 9 ms 13676 KB Output is correct
10 Correct 9 ms 13676 KB Output is correct
11 Correct 10 ms 13804 KB Output is correct
12 Correct 10 ms 13676 KB Output is correct
13 Correct 10 ms 13676 KB Output is correct
14 Correct 9 ms 13676 KB Output is correct
15 Correct 10 ms 13676 KB Output is correct
16 Correct 9 ms 13676 KB Output is correct
17 Correct 10 ms 13676 KB Output is correct
18 Correct 10 ms 13676 KB Output is correct
19 Correct 10 ms 13676 KB Output is correct
20 Correct 9 ms 13676 KB Output is correct
21 Correct 11 ms 13804 KB Output is correct
22 Correct 11 ms 13804 KB Output is correct
23 Correct 10 ms 13676 KB Output is correct
24 Correct 11 ms 13804 KB Output is correct
25 Correct 11 ms 13804 KB Output is correct
26 Correct 10 ms 13804 KB Output is correct
27 Correct 11 ms 13804 KB Output is correct
28 Correct 10 ms 13804 KB Output is correct
29 Correct 11 ms 13804 KB Output is correct
30 Correct 11 ms 13824 KB Output is correct
31 Correct 11 ms 13804 KB Output is correct
32 Correct 10 ms 13804 KB Output is correct
33 Correct 11 ms 13804 KB Output is correct
34 Correct 11 ms 13804 KB Output is correct
35 Correct 11 ms 13804 KB Output is correct
36 Correct 12 ms 13804 KB Output is correct
37 Correct 10 ms 13804 KB Output is correct
38 Correct 10 ms 13676 KB Output is correct
39 Correct 265 ms 21484 KB Output is correct
40 Correct 242 ms 21376 KB Output is correct
41 Correct 265 ms 21612 KB Output is correct
42 Correct 266 ms 21888 KB Output is correct
43 Correct 172 ms 21228 KB Output is correct
44 Correct 116 ms 21612 KB Output is correct
45 Correct 214 ms 24556 KB Output is correct
46 Correct 159 ms 28268 KB Output is correct
47 Correct 344 ms 30060 KB Output is correct
48 Correct 490 ms 41196 KB Output is correct
49 Correct 481 ms 41708 KB Output is correct
50 Correct 344 ms 31468 KB Output is correct
51 Correct 350 ms 31468 KB Output is correct
52 Correct 423 ms 31596 KB Output is correct
53 Correct 419 ms 30444 KB Output is correct
54 Correct 370 ms 30316 KB Output is correct
55 Correct 22 ms 14572 KB Output is correct
56 Correct 23 ms 14700 KB Output is correct
57 Correct 136 ms 23148 KB Output is correct
58 Correct 62 ms 23388 KB Output is correct
59 Correct 147 ms 29676 KB Output is correct
60 Correct 704 ms 43832 KB Output is correct
61 Correct 366 ms 31724 KB Output is correct
62 Correct 378 ms 32108 KB Output is correct
63 Correct 471 ms 32368 KB Output is correct
64 Correct 888 ms 31792 KB Output is correct
65 Correct 504 ms 30700 KB Output is correct
66 Correct 625 ms 39660 KB Output is correct
67 Correct 228 ms 32596 KB Output is correct
68 Correct 493 ms 31980 KB Output is correct
69 Correct 481 ms 32188 KB Output is correct
70 Correct 450 ms 31212 KB Output is correct