# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
345107 |
2021-01-07T03:07:13 Z |
daniel920712 |
Race (IOI11_race) |
C++14 |
|
737 ms |
55648 KB |
#include "race.h"
#include <vector>
#include <utility>
#include <unordered_map>
#include <assert.h>
using namespace std;
long long ans=1000000000;
bool use[200005];
long long now=2e5;
pair < long long , long long > small[1000005];
vector < pair < long long , long long > > t;
vector < pair < pair < long long , long long > , long long > > Next[200005];
vector < long long > vis;
long long how[200005];
long long big[200005];
long long tt=0;
long long KK;
long long con=0;
void F(long long fa,long long here,long long dis,long long deg,long long KK)
{
con++;
//assert(con<=100000);
if(dis>KK) return ;
if(small[KK-dis].first==now) ans=min(ans,deg+small[KK-dis].second);
if(dis==KK) return ;
t.push_back(make_pair(dis,deg));
for(auto i:Next[here]) if(i.first.first!=fa&&!use[i.first.first]) F(here,i.first.first,dis+i.first.second,deg+1,KK);
}
void DFS2(long long fa,long long here)
{
big[here]=0;
how[here]=1;
tt++;
vis.push_back(here);
for(auto i:Next[here])
{
if(i.first.first!=fa&&!use[i.first.first])
{
DFS2(here,i.first.first);
big[here]=max(big[here],how[i.first.first]);
how[here]+=how[i.first.first];
}
}
}
void DFS(long long here,long long deg)
{
assert(deg<=40);
now++;
vector < long long > ttt;
vis.clear();
tt=0;
DFS2(-1,here);
long long center;
for(auto i:vis) if(max(big[i],tt-how[i])<=tt/2) center=i;
small[0]=make_pair(now,0);
for(auto &i:Next[center])
{
if(!use[i.first.first])
{
ttt.push_back(i.first.first);
t.clear();
F(center,i.first.first,i.first.second,1,KK);
for(auto j:t)
{
if(small[j.first].first!=now) small[j.first]=make_pair(now,j.second);
else small[j.first].second=min(small[j.first].second,j.second);
}
}
}
use[center]=1;
for(auto i:ttt) DFS(i,deg+1);
}
int best_path(int N, int KK, int H[][2], int L[])
{
//assert((N<=200000));
::KK=KK;
int i;
for(i=0;i<N-1;i++)
{
Next[H[i][0]].push_back(make_pair(make_pair((long long) H[i][1],(long long) L[i]),1));
Next[H[i][1]].push_back(make_pair(make_pair((long long) H[i][0],(long long) L[i]),1));
}
DFS(0,0);
if(ans==1000000000) ans=-1;
return (int) ans;
}
Compilation message
race.cpp: In function 'void DFS(long long int, long long int)':
race.cpp:55:15: warning: 'center' may be used uninitialized in this function [-Wmaybe-uninitialized]
55 | long long center;
| ^~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
5100 KB |
Output is correct |
2 |
Correct |
5 ms |
5100 KB |
Output is correct |
3 |
Correct |
4 ms |
5100 KB |
Output is correct |
4 |
Correct |
4 ms |
5100 KB |
Output is correct |
5 |
Correct |
4 ms |
5100 KB |
Output is correct |
6 |
Correct |
4 ms |
5100 KB |
Output is correct |
7 |
Correct |
4 ms |
5100 KB |
Output is correct |
8 |
Correct |
5 ms |
5248 KB |
Output is correct |
9 |
Correct |
4 ms |
5100 KB |
Output is correct |
10 |
Correct |
4 ms |
5100 KB |
Output is correct |
11 |
Correct |
4 ms |
5100 KB |
Output is correct |
12 |
Correct |
4 ms |
5100 KB |
Output is correct |
13 |
Correct |
4 ms |
5100 KB |
Output is correct |
14 |
Correct |
4 ms |
5100 KB |
Output is correct |
15 |
Correct |
5 ms |
5048 KB |
Output is correct |
16 |
Correct |
4 ms |
5100 KB |
Output is correct |
17 |
Correct |
4 ms |
5004 KB |
Output is correct |
18 |
Correct |
4 ms |
5100 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
5100 KB |
Output is correct |
2 |
Correct |
5 ms |
5100 KB |
Output is correct |
3 |
Correct |
4 ms |
5100 KB |
Output is correct |
4 |
Correct |
4 ms |
5100 KB |
Output is correct |
5 |
Correct |
4 ms |
5100 KB |
Output is correct |
6 |
Correct |
4 ms |
5100 KB |
Output is correct |
7 |
Correct |
4 ms |
5100 KB |
Output is correct |
8 |
Correct |
5 ms |
5248 KB |
Output is correct |
9 |
Correct |
4 ms |
5100 KB |
Output is correct |
10 |
Correct |
4 ms |
5100 KB |
Output is correct |
11 |
Correct |
4 ms |
5100 KB |
Output is correct |
12 |
Correct |
4 ms |
5100 KB |
Output is correct |
13 |
Correct |
4 ms |
5100 KB |
Output is correct |
14 |
Correct |
4 ms |
5100 KB |
Output is correct |
15 |
Correct |
5 ms |
5048 KB |
Output is correct |
16 |
Correct |
4 ms |
5100 KB |
Output is correct |
17 |
Correct |
4 ms |
5004 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 |
5 ms |
5228 KB |
Output is correct |
22 |
Correct |
8 ms |
9068 KB |
Output is correct |
23 |
Correct |
10 ms |
8556 KB |
Output is correct |
24 |
Correct |
11 ms |
10220 KB |
Output is correct |
25 |
Correct |
12 ms |
10732 KB |
Output is correct |
26 |
Correct |
8 ms |
8684 KB |
Output is correct |
27 |
Correct |
4 ms |
5100 KB |
Output is correct |
28 |
Correct |
8 ms |
8172 KB |
Output is correct |
29 |
Correct |
10 ms |
9580 KB |
Output is correct |
30 |
Correct |
9 ms |
10092 KB |
Output is correct |
31 |
Correct |
11 ms |
10732 KB |
Output is correct |
32 |
Correct |
11 ms |
10860 KB |
Output is correct |
33 |
Correct |
13 ms |
13164 KB |
Output is correct |
34 |
Correct |
10 ms |
11616 KB |
Output is correct |
35 |
Correct |
11 ms |
12652 KB |
Output is correct |
36 |
Correct |
11 ms |
12940 KB |
Output is correct |
37 |
Correct |
11 ms |
10220 KB |
Output is correct |
38 |
Correct |
9 ms |
8940 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
5100 KB |
Output is correct |
2 |
Correct |
5 ms |
5100 KB |
Output is correct |
3 |
Correct |
4 ms |
5100 KB |
Output is correct |
4 |
Correct |
4 ms |
5100 KB |
Output is correct |
5 |
Correct |
4 ms |
5100 KB |
Output is correct |
6 |
Correct |
4 ms |
5100 KB |
Output is correct |
7 |
Correct |
4 ms |
5100 KB |
Output is correct |
8 |
Correct |
5 ms |
5248 KB |
Output is correct |
9 |
Correct |
4 ms |
5100 KB |
Output is correct |
10 |
Correct |
4 ms |
5100 KB |
Output is correct |
11 |
Correct |
4 ms |
5100 KB |
Output is correct |
12 |
Correct |
4 ms |
5100 KB |
Output is correct |
13 |
Correct |
4 ms |
5100 KB |
Output is correct |
14 |
Correct |
4 ms |
5100 KB |
Output is correct |
15 |
Correct |
5 ms |
5048 KB |
Output is correct |
16 |
Correct |
4 ms |
5100 KB |
Output is correct |
17 |
Correct |
4 ms |
5004 KB |
Output is correct |
18 |
Correct |
4 ms |
5100 KB |
Output is correct |
19 |
Correct |
223 ms |
16868 KB |
Output is correct |
20 |
Correct |
245 ms |
16868 KB |
Output is correct |
21 |
Correct |
271 ms |
17376 KB |
Output is correct |
22 |
Correct |
261 ms |
17636 KB |
Output is correct |
23 |
Correct |
166 ms |
17480 KB |
Output is correct |
24 |
Correct |
131 ms |
16116 KB |
Output is correct |
25 |
Correct |
192 ms |
20544 KB |
Output is correct |
26 |
Correct |
119 ms |
25568 KB |
Output is correct |
27 |
Correct |
280 ms |
28764 KB |
Output is correct |
28 |
Correct |
476 ms |
43556 KB |
Output is correct |
29 |
Correct |
472 ms |
42508 KB |
Output is correct |
30 |
Correct |
252 ms |
28764 KB |
Output is correct |
31 |
Correct |
239 ms |
28764 KB |
Output is correct |
32 |
Correct |
341 ms |
29028 KB |
Output is correct |
33 |
Correct |
391 ms |
28216 KB |
Output is correct |
34 |
Correct |
386 ms |
29152 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
5100 KB |
Output is correct |
2 |
Correct |
5 ms |
5100 KB |
Output is correct |
3 |
Correct |
4 ms |
5100 KB |
Output is correct |
4 |
Correct |
4 ms |
5100 KB |
Output is correct |
5 |
Correct |
4 ms |
5100 KB |
Output is correct |
6 |
Correct |
4 ms |
5100 KB |
Output is correct |
7 |
Correct |
4 ms |
5100 KB |
Output is correct |
8 |
Correct |
5 ms |
5248 KB |
Output is correct |
9 |
Correct |
4 ms |
5100 KB |
Output is correct |
10 |
Correct |
4 ms |
5100 KB |
Output is correct |
11 |
Correct |
4 ms |
5100 KB |
Output is correct |
12 |
Correct |
4 ms |
5100 KB |
Output is correct |
13 |
Correct |
4 ms |
5100 KB |
Output is correct |
14 |
Correct |
4 ms |
5100 KB |
Output is correct |
15 |
Correct |
5 ms |
5048 KB |
Output is correct |
16 |
Correct |
4 ms |
5100 KB |
Output is correct |
17 |
Correct |
4 ms |
5004 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 |
5 ms |
5228 KB |
Output is correct |
22 |
Correct |
8 ms |
9068 KB |
Output is correct |
23 |
Correct |
10 ms |
8556 KB |
Output is correct |
24 |
Correct |
11 ms |
10220 KB |
Output is correct |
25 |
Correct |
12 ms |
10732 KB |
Output is correct |
26 |
Correct |
8 ms |
8684 KB |
Output is correct |
27 |
Correct |
4 ms |
5100 KB |
Output is correct |
28 |
Correct |
8 ms |
8172 KB |
Output is correct |
29 |
Correct |
10 ms |
9580 KB |
Output is correct |
30 |
Correct |
9 ms |
10092 KB |
Output is correct |
31 |
Correct |
11 ms |
10732 KB |
Output is correct |
32 |
Correct |
11 ms |
10860 KB |
Output is correct |
33 |
Correct |
13 ms |
13164 KB |
Output is correct |
34 |
Correct |
10 ms |
11616 KB |
Output is correct |
35 |
Correct |
11 ms |
12652 KB |
Output is correct |
36 |
Correct |
11 ms |
12940 KB |
Output is correct |
37 |
Correct |
11 ms |
10220 KB |
Output is correct |
38 |
Correct |
9 ms |
8940 KB |
Output is correct |
39 |
Correct |
223 ms |
16868 KB |
Output is correct |
40 |
Correct |
245 ms |
16868 KB |
Output is correct |
41 |
Correct |
271 ms |
17376 KB |
Output is correct |
42 |
Correct |
261 ms |
17636 KB |
Output is correct |
43 |
Correct |
166 ms |
17480 KB |
Output is correct |
44 |
Correct |
131 ms |
16116 KB |
Output is correct |
45 |
Correct |
192 ms |
20544 KB |
Output is correct |
46 |
Correct |
119 ms |
25568 KB |
Output is correct |
47 |
Correct |
280 ms |
28764 KB |
Output is correct |
48 |
Correct |
476 ms |
43556 KB |
Output is correct |
49 |
Correct |
472 ms |
42508 KB |
Output is correct |
50 |
Correct |
252 ms |
28764 KB |
Output is correct |
51 |
Correct |
239 ms |
28764 KB |
Output is correct |
52 |
Correct |
341 ms |
29028 KB |
Output is correct |
53 |
Correct |
391 ms |
28216 KB |
Output is correct |
54 |
Correct |
386 ms |
29152 KB |
Output is correct |
55 |
Correct |
15 ms |
6380 KB |
Output is correct |
56 |
Correct |
15 ms |
6380 KB |
Output is correct |
57 |
Correct |
104 ms |
18528 KB |
Output is correct |
58 |
Correct |
50 ms |
17692 KB |
Output is correct |
59 |
Correct |
128 ms |
26592 KB |
Output is correct |
60 |
Correct |
662 ms |
53740 KB |
Output is correct |
61 |
Correct |
250 ms |
29020 KB |
Output is correct |
62 |
Correct |
268 ms |
28904 KB |
Output is correct |
63 |
Correct |
370 ms |
29028 KB |
Output is correct |
64 |
Correct |
737 ms |
34652 KB |
Output is correct |
65 |
Correct |
432 ms |
29668 KB |
Output is correct |
66 |
Correct |
638 ms |
55648 KB |
Output is correct |
67 |
Correct |
193 ms |
31248 KB |
Output is correct |
68 |
Correct |
377 ms |
38708 KB |
Output is correct |
69 |
Correct |
421 ms |
39008 KB |
Output is correct |
70 |
Correct |
376 ms |
37340 KB |
Output is correct |