# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1108354 |
2024-11-03T23:01:58 Z |
SteveBro |
Race (IOI11_race) |
C++17 |
|
235 ms |
44388 KB |
#include <bits/stdc++.h>
using namespace std;
int mat[200001][2],ll[200001],p;
const int inf=1e9;
struct ura
{
int t,s;
bool ok;
}v[200001];
vector < pair<int,int> > g[200001];
int sol;
void dfs(int nod, int n)
{
bool ok=true;
v[nod].s=1;
for(auto x : g[nod])
{
if(!v[x.first].ok&&v[nod].t!=x.first)
{
v[x.first].t=nod;
dfs(x.first,n);
v[nod].s+=v[x.first].s;
if(v[x.first].s>n/2)
ok=false;
}
}
if(n-v[nod].s>n/2)
ok=false;
if(ok)
sol=nod;
}
int vc[1000001];
vector <int> r;
int rez=inf;
void dfs1(int nod, int d, int nrm)
{
if(d<=p)
{
rez=min(rez,vc[p-d]+nrm);
for(auto x : g[nod])
{
if(!v[x.first].ok&&x.first!=v[nod].t)
{
v[x.first].t=nod;
dfs1(x.first,d+x.second,nrm+1);
}
}
}
}
void dfs2(int nod, int d, int nrm)
{
if(d<=p)
{
vc[d]=min(nrm,vc[d]);
r.push_back(d);
for(auto x : g[nod])
{
if(!v[x.first].ok&&x.first!=v[nod].t)
{
v[x.first].t=nod;
dfs2(x.first,d+x.second,nrm+1);
}
}
}
}
void divide(int nod, int nr)
{
if(nr==1)
return;
dfs(nod,nr);
int ctd=sol;
for(auto x : g[ctd])
{
if(!v[x.first].ok)
{
v[x.first].t=ctd;
dfs1(x.first,x.second,1);
dfs2(x.first,x.second,1);
}
}
for(int i=0;i<r.size();i++)
vc[r[i]]=inf;
r.clear();
v[ctd].ok=true;
v[v[ctd].t].s=nr-v[ctd].s;
for(auto x : g[ctd])
{
if(!v[x.first].ok)
{
v[x.first].t=ctd;
divide(x.first,v[x.first].s);
}
}
}
int best_path(int n,int k,int h[][2],int l[])
{
int i;
for(i=1;i<=k;i++)
vc[i]=inf;
for(i=0;i<n-1;i++)
{
g[h[i][0]].push_back(make_pair(h[i][1],l[i]));
g[h[i][1]].push_back(make_pair(h[i][0],l[i]));
}
p=k;
v[1].t=n;
divide(1,n);
if(rez==inf)
rez=-1;
return rez;
}
Compilation message
race.cpp: In function 'void divide(int, int)':
race.cpp:82:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
82 | for(int i=0;i<r.size();i++)
| ~^~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
12624 KB |
Output is correct |
2 |
Correct |
2 ms |
12624 KB |
Output is correct |
3 |
Correct |
2 ms |
12744 KB |
Output is correct |
4 |
Correct |
2 ms |
12624 KB |
Output is correct |
5 |
Correct |
2 ms |
12624 KB |
Output is correct |
6 |
Correct |
2 ms |
12624 KB |
Output is correct |
7 |
Correct |
2 ms |
12624 KB |
Output is correct |
8 |
Correct |
3 ms |
12624 KB |
Output is correct |
9 |
Correct |
2 ms |
12624 KB |
Output is correct |
10 |
Correct |
2 ms |
12624 KB |
Output is correct |
11 |
Correct |
3 ms |
12624 KB |
Output is correct |
12 |
Correct |
2 ms |
12624 KB |
Output is correct |
13 |
Correct |
2 ms |
12624 KB |
Output is correct |
14 |
Correct |
2 ms |
12624 KB |
Output is correct |
15 |
Correct |
2 ms |
12624 KB |
Output is correct |
16 |
Correct |
2 ms |
12624 KB |
Output is correct |
17 |
Correct |
2 ms |
12624 KB |
Output is correct |
18 |
Correct |
2 ms |
12624 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
12624 KB |
Output is correct |
2 |
Correct |
2 ms |
12624 KB |
Output is correct |
3 |
Correct |
2 ms |
12744 KB |
Output is correct |
4 |
Correct |
2 ms |
12624 KB |
Output is correct |
5 |
Correct |
2 ms |
12624 KB |
Output is correct |
6 |
Correct |
2 ms |
12624 KB |
Output is correct |
7 |
Correct |
2 ms |
12624 KB |
Output is correct |
8 |
Correct |
3 ms |
12624 KB |
Output is correct |
9 |
Correct |
2 ms |
12624 KB |
Output is correct |
10 |
Correct |
2 ms |
12624 KB |
Output is correct |
11 |
Correct |
3 ms |
12624 KB |
Output is correct |
12 |
Correct |
2 ms |
12624 KB |
Output is correct |
13 |
Correct |
2 ms |
12624 KB |
Output is correct |
14 |
Correct |
2 ms |
12624 KB |
Output is correct |
15 |
Correct |
2 ms |
12624 KB |
Output is correct |
16 |
Correct |
2 ms |
12624 KB |
Output is correct |
17 |
Correct |
2 ms |
12624 KB |
Output is correct |
18 |
Correct |
2 ms |
12624 KB |
Output is correct |
19 |
Correct |
2 ms |
12624 KB |
Output is correct |
20 |
Correct |
2 ms |
12624 KB |
Output is correct |
21 |
Correct |
2 ms |
12732 KB |
Output is correct |
22 |
Correct |
3 ms |
14672 KB |
Output is correct |
23 |
Correct |
3 ms |
14672 KB |
Output is correct |
24 |
Correct |
3 ms |
14672 KB |
Output is correct |
25 |
Correct |
3 ms |
14672 KB |
Output is correct |
26 |
Correct |
3 ms |
14672 KB |
Output is correct |
27 |
Correct |
3 ms |
14672 KB |
Output is correct |
28 |
Correct |
3 ms |
14672 KB |
Output is correct |
29 |
Correct |
3 ms |
14672 KB |
Output is correct |
30 |
Correct |
4 ms |
14672 KB |
Output is correct |
31 |
Correct |
3 ms |
14672 KB |
Output is correct |
32 |
Correct |
3 ms |
14672 KB |
Output is correct |
33 |
Correct |
4 ms |
14672 KB |
Output is correct |
34 |
Correct |
3 ms |
14672 KB |
Output is correct |
35 |
Correct |
3 ms |
14672 KB |
Output is correct |
36 |
Correct |
4 ms |
14928 KB |
Output is correct |
37 |
Correct |
3 ms |
14672 KB |
Output is correct |
38 |
Correct |
3 ms |
14672 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
12624 KB |
Output is correct |
2 |
Correct |
2 ms |
12624 KB |
Output is correct |
3 |
Correct |
2 ms |
12744 KB |
Output is correct |
4 |
Correct |
2 ms |
12624 KB |
Output is correct |
5 |
Correct |
2 ms |
12624 KB |
Output is correct |
6 |
Correct |
2 ms |
12624 KB |
Output is correct |
7 |
Correct |
2 ms |
12624 KB |
Output is correct |
8 |
Correct |
3 ms |
12624 KB |
Output is correct |
9 |
Correct |
2 ms |
12624 KB |
Output is correct |
10 |
Correct |
2 ms |
12624 KB |
Output is correct |
11 |
Correct |
3 ms |
12624 KB |
Output is correct |
12 |
Correct |
2 ms |
12624 KB |
Output is correct |
13 |
Correct |
2 ms |
12624 KB |
Output is correct |
14 |
Correct |
2 ms |
12624 KB |
Output is correct |
15 |
Correct |
2 ms |
12624 KB |
Output is correct |
16 |
Correct |
2 ms |
12624 KB |
Output is correct |
17 |
Correct |
2 ms |
12624 KB |
Output is correct |
18 |
Correct |
2 ms |
12624 KB |
Output is correct |
19 |
Correct |
73 ms |
19784 KB |
Output is correct |
20 |
Correct |
71 ms |
19792 KB |
Output is correct |
21 |
Correct |
77 ms |
20044 KB |
Output is correct |
22 |
Correct |
77 ms |
20420 KB |
Output is correct |
23 |
Correct |
47 ms |
19768 KB |
Output is correct |
24 |
Correct |
35 ms |
19792 KB |
Output is correct |
25 |
Correct |
84 ms |
27512 KB |
Output is correct |
26 |
Correct |
68 ms |
29140 KB |
Output is correct |
27 |
Correct |
89 ms |
24648 KB |
Output is correct |
28 |
Correct |
142 ms |
40520 KB |
Output is correct |
29 |
Correct |
151 ms |
34428 KB |
Output is correct |
30 |
Correct |
91 ms |
24444 KB |
Output is correct |
31 |
Correct |
90 ms |
24648 KB |
Output is correct |
32 |
Correct |
98 ms |
24572 KB |
Output is correct |
33 |
Correct |
117 ms |
23412 KB |
Output is correct |
34 |
Correct |
99 ms |
23368 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
12624 KB |
Output is correct |
2 |
Correct |
2 ms |
12624 KB |
Output is correct |
3 |
Correct |
2 ms |
12744 KB |
Output is correct |
4 |
Correct |
2 ms |
12624 KB |
Output is correct |
5 |
Correct |
2 ms |
12624 KB |
Output is correct |
6 |
Correct |
2 ms |
12624 KB |
Output is correct |
7 |
Correct |
2 ms |
12624 KB |
Output is correct |
8 |
Correct |
3 ms |
12624 KB |
Output is correct |
9 |
Correct |
2 ms |
12624 KB |
Output is correct |
10 |
Correct |
2 ms |
12624 KB |
Output is correct |
11 |
Correct |
3 ms |
12624 KB |
Output is correct |
12 |
Correct |
2 ms |
12624 KB |
Output is correct |
13 |
Correct |
2 ms |
12624 KB |
Output is correct |
14 |
Correct |
2 ms |
12624 KB |
Output is correct |
15 |
Correct |
2 ms |
12624 KB |
Output is correct |
16 |
Correct |
2 ms |
12624 KB |
Output is correct |
17 |
Correct |
2 ms |
12624 KB |
Output is correct |
18 |
Correct |
2 ms |
12624 KB |
Output is correct |
19 |
Correct |
2 ms |
12624 KB |
Output is correct |
20 |
Correct |
2 ms |
12624 KB |
Output is correct |
21 |
Correct |
2 ms |
12732 KB |
Output is correct |
22 |
Correct |
3 ms |
14672 KB |
Output is correct |
23 |
Correct |
3 ms |
14672 KB |
Output is correct |
24 |
Correct |
3 ms |
14672 KB |
Output is correct |
25 |
Correct |
3 ms |
14672 KB |
Output is correct |
26 |
Correct |
3 ms |
14672 KB |
Output is correct |
27 |
Correct |
3 ms |
14672 KB |
Output is correct |
28 |
Correct |
3 ms |
14672 KB |
Output is correct |
29 |
Correct |
3 ms |
14672 KB |
Output is correct |
30 |
Correct |
4 ms |
14672 KB |
Output is correct |
31 |
Correct |
3 ms |
14672 KB |
Output is correct |
32 |
Correct |
3 ms |
14672 KB |
Output is correct |
33 |
Correct |
4 ms |
14672 KB |
Output is correct |
34 |
Correct |
3 ms |
14672 KB |
Output is correct |
35 |
Correct |
3 ms |
14672 KB |
Output is correct |
36 |
Correct |
4 ms |
14928 KB |
Output is correct |
37 |
Correct |
3 ms |
14672 KB |
Output is correct |
38 |
Correct |
3 ms |
14672 KB |
Output is correct |
39 |
Correct |
73 ms |
19784 KB |
Output is correct |
40 |
Correct |
71 ms |
19792 KB |
Output is correct |
41 |
Correct |
77 ms |
20044 KB |
Output is correct |
42 |
Correct |
77 ms |
20420 KB |
Output is correct |
43 |
Correct |
47 ms |
19768 KB |
Output is correct |
44 |
Correct |
35 ms |
19792 KB |
Output is correct |
45 |
Correct |
84 ms |
27512 KB |
Output is correct |
46 |
Correct |
68 ms |
29140 KB |
Output is correct |
47 |
Correct |
89 ms |
24648 KB |
Output is correct |
48 |
Correct |
142 ms |
40520 KB |
Output is correct |
49 |
Correct |
151 ms |
34428 KB |
Output is correct |
50 |
Correct |
91 ms |
24444 KB |
Output is correct |
51 |
Correct |
90 ms |
24648 KB |
Output is correct |
52 |
Correct |
98 ms |
24572 KB |
Output is correct |
53 |
Correct |
117 ms |
23412 KB |
Output is correct |
54 |
Correct |
99 ms |
23368 KB |
Output is correct |
55 |
Correct |
7 ms |
13136 KB |
Output is correct |
56 |
Correct |
8 ms |
13136 KB |
Output is correct |
57 |
Correct |
49 ms |
20584 KB |
Output is correct |
58 |
Correct |
24 ms |
20676 KB |
Output is correct |
59 |
Correct |
70 ms |
31204 KB |
Output is correct |
60 |
Correct |
229 ms |
36080 KB |
Output is correct |
61 |
Correct |
104 ms |
27976 KB |
Output is correct |
62 |
Correct |
117 ms |
30660 KB |
Output is correct |
63 |
Correct |
130 ms |
30824 KB |
Output is correct |
64 |
Correct |
235 ms |
30912 KB |
Output is correct |
65 |
Correct |
114 ms |
28136 KB |
Output is correct |
66 |
Correct |
181 ms |
44388 KB |
Output is correct |
67 |
Correct |
56 ms |
32452 KB |
Output is correct |
68 |
Correct |
114 ms |
30916 KB |
Output is correct |
69 |
Correct |
114 ms |
31088 KB |
Output is correct |
70 |
Correct |
111 ms |
30660 KB |
Output is correct |