# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
88008 |
2018-12-03T11:17:41 Z |
Pajaraja |
Race (IOI11_race) |
C++17 |
|
1166 ms |
107076 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;
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);
}
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:13:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
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:20:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
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:35:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
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:43:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0;i<g[c].size();i++) if(!vi[g[c][i]])
~^~~~~~~~~~~~
race.cpp:65:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
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 |
15 ms |
13816 KB |
Output is correct |
2 |
Correct |
15 ms |
13936 KB |
Output is correct |
3 |
Correct |
14 ms |
13988 KB |
Output is correct |
4 |
Correct |
14 ms |
13988 KB |
Output is correct |
5 |
Correct |
15 ms |
13988 KB |
Output is correct |
6 |
Correct |
15 ms |
14028 KB |
Output is correct |
7 |
Correct |
14 ms |
14128 KB |
Output is correct |
8 |
Correct |
17 ms |
14228 KB |
Output is correct |
9 |
Correct |
17 ms |
14228 KB |
Output is correct |
10 |
Correct |
17 ms |
14228 KB |
Output is correct |
11 |
Correct |
16 ms |
14228 KB |
Output is correct |
12 |
Correct |
17 ms |
14228 KB |
Output is correct |
13 |
Correct |
16 ms |
14228 KB |
Output is correct |
14 |
Correct |
15 ms |
14228 KB |
Output is correct |
15 |
Correct |
15 ms |
14228 KB |
Output is correct |
16 |
Correct |
17 ms |
14228 KB |
Output is correct |
17 |
Correct |
16 ms |
14232 KB |
Output is correct |
18 |
Correct |
17 ms |
14236 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
13816 KB |
Output is correct |
2 |
Correct |
15 ms |
13936 KB |
Output is correct |
3 |
Correct |
14 ms |
13988 KB |
Output is correct |
4 |
Correct |
14 ms |
13988 KB |
Output is correct |
5 |
Correct |
15 ms |
13988 KB |
Output is correct |
6 |
Correct |
15 ms |
14028 KB |
Output is correct |
7 |
Correct |
14 ms |
14128 KB |
Output is correct |
8 |
Correct |
17 ms |
14228 KB |
Output is correct |
9 |
Correct |
17 ms |
14228 KB |
Output is correct |
10 |
Correct |
17 ms |
14228 KB |
Output is correct |
11 |
Correct |
16 ms |
14228 KB |
Output is correct |
12 |
Correct |
17 ms |
14228 KB |
Output is correct |
13 |
Correct |
16 ms |
14228 KB |
Output is correct |
14 |
Correct |
15 ms |
14228 KB |
Output is correct |
15 |
Correct |
15 ms |
14228 KB |
Output is correct |
16 |
Correct |
17 ms |
14228 KB |
Output is correct |
17 |
Correct |
16 ms |
14232 KB |
Output is correct |
18 |
Correct |
17 ms |
14236 KB |
Output is correct |
19 |
Correct |
17 ms |
14240 KB |
Output is correct |
20 |
Correct |
16 ms |
14240 KB |
Output is correct |
21 |
Correct |
16 ms |
14248 KB |
Output is correct |
22 |
Correct |
17 ms |
14280 KB |
Output is correct |
23 |
Correct |
15 ms |
14292 KB |
Output is correct |
24 |
Correct |
16 ms |
14308 KB |
Output is correct |
25 |
Correct |
16 ms |
14324 KB |
Output is correct |
26 |
Correct |
16 ms |
14356 KB |
Output is correct |
27 |
Correct |
17 ms |
14388 KB |
Output is correct |
28 |
Correct |
16 ms |
14404 KB |
Output is correct |
29 |
Correct |
16 ms |
14420 KB |
Output is correct |
30 |
Correct |
16 ms |
14452 KB |
Output is correct |
31 |
Correct |
16 ms |
14468 KB |
Output is correct |
32 |
Correct |
16 ms |
14484 KB |
Output is correct |
33 |
Correct |
51 ms |
14500 KB |
Output is correct |
34 |
Correct |
15 ms |
14580 KB |
Output is correct |
35 |
Correct |
15 ms |
14580 KB |
Output is correct |
36 |
Correct |
15 ms |
14580 KB |
Output is correct |
37 |
Correct |
16 ms |
14620 KB |
Output is correct |
38 |
Correct |
16 ms |
14620 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
13816 KB |
Output is correct |
2 |
Correct |
15 ms |
13936 KB |
Output is correct |
3 |
Correct |
14 ms |
13988 KB |
Output is correct |
4 |
Correct |
14 ms |
13988 KB |
Output is correct |
5 |
Correct |
15 ms |
13988 KB |
Output is correct |
6 |
Correct |
15 ms |
14028 KB |
Output is correct |
7 |
Correct |
14 ms |
14128 KB |
Output is correct |
8 |
Correct |
17 ms |
14228 KB |
Output is correct |
9 |
Correct |
17 ms |
14228 KB |
Output is correct |
10 |
Correct |
17 ms |
14228 KB |
Output is correct |
11 |
Correct |
16 ms |
14228 KB |
Output is correct |
12 |
Correct |
17 ms |
14228 KB |
Output is correct |
13 |
Correct |
16 ms |
14228 KB |
Output is correct |
14 |
Correct |
15 ms |
14228 KB |
Output is correct |
15 |
Correct |
15 ms |
14228 KB |
Output is correct |
16 |
Correct |
17 ms |
14228 KB |
Output is correct |
17 |
Correct |
16 ms |
14232 KB |
Output is correct |
18 |
Correct |
17 ms |
14236 KB |
Output is correct |
19 |
Correct |
324 ms |
23600 KB |
Output is correct |
20 |
Correct |
260 ms |
25048 KB |
Output is correct |
21 |
Correct |
263 ms |
26608 KB |
Output is correct |
22 |
Correct |
262 ms |
28204 KB |
Output is correct |
23 |
Correct |
199 ms |
29004 KB |
Output is correct |
24 |
Correct |
180 ms |
30928 KB |
Output is correct |
25 |
Correct |
310 ms |
36020 KB |
Output is correct |
26 |
Correct |
202 ms |
41844 KB |
Output is correct |
27 |
Correct |
557 ms |
44756 KB |
Output is correct |
28 |
Correct |
776 ms |
62324 KB |
Output is correct |
29 |
Correct |
737 ms |
64240 KB |
Output is correct |
30 |
Correct |
532 ms |
64240 KB |
Output is correct |
31 |
Correct |
412 ms |
64240 KB |
Output is correct |
32 |
Correct |
519 ms |
64240 KB |
Output is correct |
33 |
Correct |
644 ms |
64240 KB |
Output is correct |
34 |
Correct |
577 ms |
65516 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
13816 KB |
Output is correct |
2 |
Correct |
15 ms |
13936 KB |
Output is correct |
3 |
Correct |
14 ms |
13988 KB |
Output is correct |
4 |
Correct |
14 ms |
13988 KB |
Output is correct |
5 |
Correct |
15 ms |
13988 KB |
Output is correct |
6 |
Correct |
15 ms |
14028 KB |
Output is correct |
7 |
Correct |
14 ms |
14128 KB |
Output is correct |
8 |
Correct |
17 ms |
14228 KB |
Output is correct |
9 |
Correct |
17 ms |
14228 KB |
Output is correct |
10 |
Correct |
17 ms |
14228 KB |
Output is correct |
11 |
Correct |
16 ms |
14228 KB |
Output is correct |
12 |
Correct |
17 ms |
14228 KB |
Output is correct |
13 |
Correct |
16 ms |
14228 KB |
Output is correct |
14 |
Correct |
15 ms |
14228 KB |
Output is correct |
15 |
Correct |
15 ms |
14228 KB |
Output is correct |
16 |
Correct |
17 ms |
14228 KB |
Output is correct |
17 |
Correct |
16 ms |
14232 KB |
Output is correct |
18 |
Correct |
17 ms |
14236 KB |
Output is correct |
19 |
Correct |
17 ms |
14240 KB |
Output is correct |
20 |
Correct |
16 ms |
14240 KB |
Output is correct |
21 |
Correct |
16 ms |
14248 KB |
Output is correct |
22 |
Correct |
17 ms |
14280 KB |
Output is correct |
23 |
Correct |
15 ms |
14292 KB |
Output is correct |
24 |
Correct |
16 ms |
14308 KB |
Output is correct |
25 |
Correct |
16 ms |
14324 KB |
Output is correct |
26 |
Correct |
16 ms |
14356 KB |
Output is correct |
27 |
Correct |
17 ms |
14388 KB |
Output is correct |
28 |
Correct |
16 ms |
14404 KB |
Output is correct |
29 |
Correct |
16 ms |
14420 KB |
Output is correct |
30 |
Correct |
16 ms |
14452 KB |
Output is correct |
31 |
Correct |
16 ms |
14468 KB |
Output is correct |
32 |
Correct |
16 ms |
14484 KB |
Output is correct |
33 |
Correct |
51 ms |
14500 KB |
Output is correct |
34 |
Correct |
15 ms |
14580 KB |
Output is correct |
35 |
Correct |
15 ms |
14580 KB |
Output is correct |
36 |
Correct |
15 ms |
14580 KB |
Output is correct |
37 |
Correct |
16 ms |
14620 KB |
Output is correct |
38 |
Correct |
16 ms |
14620 KB |
Output is correct |
39 |
Correct |
324 ms |
23600 KB |
Output is correct |
40 |
Correct |
260 ms |
25048 KB |
Output is correct |
41 |
Correct |
263 ms |
26608 KB |
Output is correct |
42 |
Correct |
262 ms |
28204 KB |
Output is correct |
43 |
Correct |
199 ms |
29004 KB |
Output is correct |
44 |
Correct |
180 ms |
30928 KB |
Output is correct |
45 |
Correct |
310 ms |
36020 KB |
Output is correct |
46 |
Correct |
202 ms |
41844 KB |
Output is correct |
47 |
Correct |
557 ms |
44756 KB |
Output is correct |
48 |
Correct |
776 ms |
62324 KB |
Output is correct |
49 |
Correct |
737 ms |
64240 KB |
Output is correct |
50 |
Correct |
532 ms |
64240 KB |
Output is correct |
51 |
Correct |
412 ms |
64240 KB |
Output is correct |
52 |
Correct |
519 ms |
64240 KB |
Output is correct |
53 |
Correct |
644 ms |
64240 KB |
Output is correct |
54 |
Correct |
577 ms |
65516 KB |
Output is correct |
55 |
Correct |
29 ms |
65516 KB |
Output is correct |
56 |
Correct |
30 ms |
65516 KB |
Output is correct |
57 |
Correct |
163 ms |
65516 KB |
Output is correct |
58 |
Correct |
79 ms |
65516 KB |
Output is correct |
59 |
Correct |
207 ms |
70424 KB |
Output is correct |
60 |
Correct |
1000 ms |
88788 KB |
Output is correct |
61 |
Correct |
442 ms |
88788 KB |
Output is correct |
62 |
Correct |
479 ms |
88788 KB |
Output is correct |
63 |
Correct |
608 ms |
88788 KB |
Output is correct |
64 |
Correct |
1166 ms |
88788 KB |
Output is correct |
65 |
Correct |
596 ms |
89272 KB |
Output is correct |
66 |
Correct |
992 ms |
104064 KB |
Output is correct |
67 |
Correct |
389 ms |
104064 KB |
Output is correct |
68 |
Correct |
746 ms |
104064 KB |
Output is correct |
69 |
Correct |
609 ms |
104460 KB |
Output is correct |
70 |
Correct |
507 ms |
107076 KB |
Output is correct |