# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
59273 |
2018-07-21T11:24:58 Z |
TadijaSebez |
Race (IOI11_race) |
C++11 |
|
863 ms |
96764 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;
}
/*int h[N][2],l[N];
int main()
{
int n,k,i;
scanf("%i %i",&n,&k);
for(i=0;i<n-1;i++) scanf("%i %i %i",&h[i][0],&h[i][1],&l[i]);
printf("%i\n",best_path(n,k,h,l));
return 0;
}*/
Compilation message
race.cpp: In function 'void DFS(int, int, int&)':
race.cpp:20:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0;i<E[u].size();i++)
~^~~~~~~~~~~~
race.cpp: In function 'int Find(int, int, int)':
race.cpp:28:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
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 between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0;i<E[u].size();i++)
~^~~~~~~~~~~~
race.cpp: In function 'void Decompose(int)':
race.cpp:57:11: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(i=0;i<E[u].size();i++)
~^~~~~~~~~~~~
race.cpp:64:13: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
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 between signed and unsigned integer expressions [-Wsign-compare]
for(i=0;i<lzy.size();i++) Min[lzy[i].first]=inf;
~^~~~~~~~~~~
race.cpp:70:11: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(i=0;i<E[u].size();i++)
~^~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
4984 KB |
Output is correct |
2 |
Correct |
8 ms |
5224 KB |
Output is correct |
3 |
Correct |
7 ms |
5224 KB |
Output is correct |
4 |
Correct |
8 ms |
5264 KB |
Output is correct |
5 |
Correct |
7 ms |
5336 KB |
Output is correct |
6 |
Correct |
7 ms |
5336 KB |
Output is correct |
7 |
Correct |
7 ms |
5412 KB |
Output is correct |
8 |
Correct |
7 ms |
5412 KB |
Output is correct |
9 |
Correct |
8 ms |
5412 KB |
Output is correct |
10 |
Correct |
8 ms |
5420 KB |
Output is correct |
11 |
Correct |
7 ms |
5536 KB |
Output is correct |
12 |
Correct |
7 ms |
5536 KB |
Output is correct |
13 |
Correct |
8 ms |
5536 KB |
Output is correct |
14 |
Correct |
7 ms |
5552 KB |
Output is correct |
15 |
Correct |
7 ms |
5552 KB |
Output is correct |
16 |
Correct |
7 ms |
5600 KB |
Output is correct |
17 |
Correct |
10 ms |
5600 KB |
Output is correct |
18 |
Correct |
8 ms |
5600 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
4984 KB |
Output is correct |
2 |
Correct |
8 ms |
5224 KB |
Output is correct |
3 |
Correct |
7 ms |
5224 KB |
Output is correct |
4 |
Correct |
8 ms |
5264 KB |
Output is correct |
5 |
Correct |
7 ms |
5336 KB |
Output is correct |
6 |
Correct |
7 ms |
5336 KB |
Output is correct |
7 |
Correct |
7 ms |
5412 KB |
Output is correct |
8 |
Correct |
7 ms |
5412 KB |
Output is correct |
9 |
Correct |
8 ms |
5412 KB |
Output is correct |
10 |
Correct |
8 ms |
5420 KB |
Output is correct |
11 |
Correct |
7 ms |
5536 KB |
Output is correct |
12 |
Correct |
7 ms |
5536 KB |
Output is correct |
13 |
Correct |
8 ms |
5536 KB |
Output is correct |
14 |
Correct |
7 ms |
5552 KB |
Output is correct |
15 |
Correct |
7 ms |
5552 KB |
Output is correct |
16 |
Correct |
7 ms |
5600 KB |
Output is correct |
17 |
Correct |
10 ms |
5600 KB |
Output is correct |
18 |
Correct |
8 ms |
5600 KB |
Output is correct |
19 |
Correct |
9 ms |
5600 KB |
Output is correct |
20 |
Correct |
7 ms |
5600 KB |
Output is correct |
21 |
Correct |
7 ms |
5600 KB |
Output is correct |
22 |
Correct |
15 ms |
9252 KB |
Output is correct |
23 |
Correct |
10 ms |
9252 KB |
Output is correct |
24 |
Correct |
10 ms |
9252 KB |
Output is correct |
25 |
Correct |
10 ms |
9252 KB |
Output is correct |
26 |
Correct |
11 ms |
9252 KB |
Output is correct |
27 |
Correct |
13 ms |
9252 KB |
Output is correct |
28 |
Correct |
10 ms |
9252 KB |
Output is correct |
29 |
Correct |
10 ms |
9252 KB |
Output is correct |
30 |
Correct |
11 ms |
9252 KB |
Output is correct |
31 |
Correct |
13 ms |
9252 KB |
Output is correct |
32 |
Correct |
12 ms |
9252 KB |
Output is correct |
33 |
Correct |
13 ms |
9252 KB |
Output is correct |
34 |
Correct |
11 ms |
9252 KB |
Output is correct |
35 |
Correct |
12 ms |
9252 KB |
Output is correct |
36 |
Correct |
11 ms |
9496 KB |
Output is correct |
37 |
Correct |
10 ms |
9496 KB |
Output is correct |
38 |
Correct |
9 ms |
9496 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
4984 KB |
Output is correct |
2 |
Correct |
8 ms |
5224 KB |
Output is correct |
3 |
Correct |
7 ms |
5224 KB |
Output is correct |
4 |
Correct |
8 ms |
5264 KB |
Output is correct |
5 |
Correct |
7 ms |
5336 KB |
Output is correct |
6 |
Correct |
7 ms |
5336 KB |
Output is correct |
7 |
Correct |
7 ms |
5412 KB |
Output is correct |
8 |
Correct |
7 ms |
5412 KB |
Output is correct |
9 |
Correct |
8 ms |
5412 KB |
Output is correct |
10 |
Correct |
8 ms |
5420 KB |
Output is correct |
11 |
Correct |
7 ms |
5536 KB |
Output is correct |
12 |
Correct |
7 ms |
5536 KB |
Output is correct |
13 |
Correct |
8 ms |
5536 KB |
Output is correct |
14 |
Correct |
7 ms |
5552 KB |
Output is correct |
15 |
Correct |
7 ms |
5552 KB |
Output is correct |
16 |
Correct |
7 ms |
5600 KB |
Output is correct |
17 |
Correct |
10 ms |
5600 KB |
Output is correct |
18 |
Correct |
8 ms |
5600 KB |
Output is correct |
19 |
Correct |
268 ms |
12872 KB |
Output is correct |
20 |
Correct |
204 ms |
14116 KB |
Output is correct |
21 |
Correct |
222 ms |
16116 KB |
Output is correct |
22 |
Correct |
200 ms |
17976 KB |
Output is correct |
23 |
Correct |
187 ms |
18428 KB |
Output is correct |
24 |
Correct |
142 ms |
19584 KB |
Output is correct |
25 |
Correct |
334 ms |
24536 KB |
Output is correct |
26 |
Correct |
173 ms |
31184 KB |
Output is correct |
27 |
Correct |
236 ms |
31184 KB |
Output is correct |
28 |
Correct |
627 ms |
47940 KB |
Output is correct |
29 |
Correct |
507 ms |
49940 KB |
Output is correct |
30 |
Correct |
282 ms |
49940 KB |
Output is correct |
31 |
Correct |
302 ms |
49940 KB |
Output is correct |
32 |
Correct |
308 ms |
49940 KB |
Output is correct |
33 |
Correct |
383 ms |
49940 KB |
Output is correct |
34 |
Correct |
445 ms |
51140 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
4984 KB |
Output is correct |
2 |
Correct |
8 ms |
5224 KB |
Output is correct |
3 |
Correct |
7 ms |
5224 KB |
Output is correct |
4 |
Correct |
8 ms |
5264 KB |
Output is correct |
5 |
Correct |
7 ms |
5336 KB |
Output is correct |
6 |
Correct |
7 ms |
5336 KB |
Output is correct |
7 |
Correct |
7 ms |
5412 KB |
Output is correct |
8 |
Correct |
7 ms |
5412 KB |
Output is correct |
9 |
Correct |
8 ms |
5412 KB |
Output is correct |
10 |
Correct |
8 ms |
5420 KB |
Output is correct |
11 |
Correct |
7 ms |
5536 KB |
Output is correct |
12 |
Correct |
7 ms |
5536 KB |
Output is correct |
13 |
Correct |
8 ms |
5536 KB |
Output is correct |
14 |
Correct |
7 ms |
5552 KB |
Output is correct |
15 |
Correct |
7 ms |
5552 KB |
Output is correct |
16 |
Correct |
7 ms |
5600 KB |
Output is correct |
17 |
Correct |
10 ms |
5600 KB |
Output is correct |
18 |
Correct |
8 ms |
5600 KB |
Output is correct |
19 |
Correct |
9 ms |
5600 KB |
Output is correct |
20 |
Correct |
7 ms |
5600 KB |
Output is correct |
21 |
Correct |
7 ms |
5600 KB |
Output is correct |
22 |
Correct |
15 ms |
9252 KB |
Output is correct |
23 |
Correct |
10 ms |
9252 KB |
Output is correct |
24 |
Correct |
10 ms |
9252 KB |
Output is correct |
25 |
Correct |
10 ms |
9252 KB |
Output is correct |
26 |
Correct |
11 ms |
9252 KB |
Output is correct |
27 |
Correct |
13 ms |
9252 KB |
Output is correct |
28 |
Correct |
10 ms |
9252 KB |
Output is correct |
29 |
Correct |
10 ms |
9252 KB |
Output is correct |
30 |
Correct |
11 ms |
9252 KB |
Output is correct |
31 |
Correct |
13 ms |
9252 KB |
Output is correct |
32 |
Correct |
12 ms |
9252 KB |
Output is correct |
33 |
Correct |
13 ms |
9252 KB |
Output is correct |
34 |
Correct |
11 ms |
9252 KB |
Output is correct |
35 |
Correct |
12 ms |
9252 KB |
Output is correct |
36 |
Correct |
11 ms |
9496 KB |
Output is correct |
37 |
Correct |
10 ms |
9496 KB |
Output is correct |
38 |
Correct |
9 ms |
9496 KB |
Output is correct |
39 |
Correct |
268 ms |
12872 KB |
Output is correct |
40 |
Correct |
204 ms |
14116 KB |
Output is correct |
41 |
Correct |
222 ms |
16116 KB |
Output is correct |
42 |
Correct |
200 ms |
17976 KB |
Output is correct |
43 |
Correct |
187 ms |
18428 KB |
Output is correct |
44 |
Correct |
142 ms |
19584 KB |
Output is correct |
45 |
Correct |
334 ms |
24536 KB |
Output is correct |
46 |
Correct |
173 ms |
31184 KB |
Output is correct |
47 |
Correct |
236 ms |
31184 KB |
Output is correct |
48 |
Correct |
627 ms |
47940 KB |
Output is correct |
49 |
Correct |
507 ms |
49940 KB |
Output is correct |
50 |
Correct |
282 ms |
49940 KB |
Output is correct |
51 |
Correct |
302 ms |
49940 KB |
Output is correct |
52 |
Correct |
308 ms |
49940 KB |
Output is correct |
53 |
Correct |
383 ms |
49940 KB |
Output is correct |
54 |
Correct |
445 ms |
51140 KB |
Output is correct |
55 |
Correct |
18 ms |
51140 KB |
Output is correct |
56 |
Correct |
19 ms |
51140 KB |
Output is correct |
57 |
Correct |
112 ms |
51140 KB |
Output is correct |
58 |
Correct |
61 ms |
51140 KB |
Output is correct |
59 |
Correct |
163 ms |
60120 KB |
Output is correct |
60 |
Correct |
671 ms |
79032 KB |
Output is correct |
61 |
Correct |
322 ms |
79032 KB |
Output is correct |
62 |
Correct |
342 ms |
79032 KB |
Output is correct |
63 |
Correct |
446 ms |
79032 KB |
Output is correct |
64 |
Correct |
863 ms |
79032 KB |
Output is correct |
65 |
Correct |
427 ms |
79032 KB |
Output is correct |
66 |
Correct |
624 ms |
92788 KB |
Output is correct |
67 |
Correct |
218 ms |
92788 KB |
Output is correct |
68 |
Correct |
444 ms |
92788 KB |
Output is correct |
69 |
Correct |
441 ms |
93952 KB |
Output is correct |
70 |
Correct |
365 ms |
96764 KB |
Output is correct |