# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
106646 |
2019-04-19T10:59:35 Z |
doowey |
Race (IOI11_race) |
C++14 |
|
819 ms |
36156 KB |
#include <bits/stdc++.h>
#include "race.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define fi first
#define se second
#define mp make_pair
const int N = (int)2e5 + 9;
const int MX = (int)1e6 + 9;
const int inf = (int)1e9 + 1;
int K;
int bes[MX];
vector<pii> T[N];
bool use[MX];
int subt[N];
int res = inf;
void dfs1(int u, int par){
subt[u] = 1;
for(auto x : T[u]){
if(use[x.fi] || x.fi == par) continue;
dfs1(x.fi, u);
subt[u] += subt[x.fi];
}
}
vector<pii> dd;
void dfs2(int u, int par, int sd, int ln){
if(sd > K)
return;
dd.push_back(mp(sd, ln));
for(auto x : T[u]){
if(use[x.fi] || x.fi == par) continue;
dfs2(x.fi, u, sd + x.se, ln + 1);
}
}
void split(int node){
dfs1(node, -1);
int par = -1;
int atl = subt[node] / 2;
bool ok = true;
while(ok){
ok = false;
for(auto x : T[node]){
if(x.fi == par || use[x.fi])continue;
if(subt[x.fi] > atl){
par = node;
node = x.fi;
ok = true;
break;
}
}
}
bes[0] = 0;
vector<int> er;
for(auto x : T[node]){
if(use[x.fi]) continue;
dd.clear();
dfs2(x.fi, node, x.se, +1);
for(auto p : dd){
res = min(res, p.se + bes[K - p.fi]);
er.push_back(p.fi);
}
for(auto p : dd){
bes[p.fi] = min(bes[p.fi], p.se);
}
}
for(auto x : er)
bes[x] = inf;
use[node] = true;
for(auto x : T[node]){
if(!use[x.fi])
split(x.fi);
}
}
int best_path(int n, int k, int h[][2], int ln[]){
K = k;
for(int i = 0 ;i < MX; i ++ )
bes[i] = inf;
for(int i = 0 ; i < n- 1; i ++ ){
T[h[i][0]].push_back(mp(h[i][1], ln[i]));
T[h[i][1]].push_back(mp(h[i][0], ln[i]));
}
split(0);
return (res == inf ? -1 : res);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
8960 KB |
Output is correct |
2 |
Correct |
10 ms |
8960 KB |
Output is correct |
3 |
Correct |
8 ms |
8960 KB |
Output is correct |
4 |
Correct |
11 ms |
8960 KB |
Output is correct |
5 |
Correct |
9 ms |
8948 KB |
Output is correct |
6 |
Correct |
10 ms |
8960 KB |
Output is correct |
7 |
Correct |
10 ms |
9008 KB |
Output is correct |
8 |
Correct |
10 ms |
8960 KB |
Output is correct |
9 |
Correct |
11 ms |
8960 KB |
Output is correct |
10 |
Correct |
13 ms |
8960 KB |
Output is correct |
11 |
Correct |
9 ms |
8960 KB |
Output is correct |
12 |
Correct |
11 ms |
8960 KB |
Output is correct |
13 |
Correct |
10 ms |
8960 KB |
Output is correct |
14 |
Correct |
14 ms |
8960 KB |
Output is correct |
15 |
Correct |
10 ms |
8960 KB |
Output is correct |
16 |
Correct |
10 ms |
8960 KB |
Output is correct |
17 |
Correct |
11 ms |
8980 KB |
Output is correct |
18 |
Correct |
12 ms |
8960 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
8960 KB |
Output is correct |
2 |
Correct |
10 ms |
8960 KB |
Output is correct |
3 |
Correct |
8 ms |
8960 KB |
Output is correct |
4 |
Correct |
11 ms |
8960 KB |
Output is correct |
5 |
Correct |
9 ms |
8948 KB |
Output is correct |
6 |
Correct |
10 ms |
8960 KB |
Output is correct |
7 |
Correct |
10 ms |
9008 KB |
Output is correct |
8 |
Correct |
10 ms |
8960 KB |
Output is correct |
9 |
Correct |
11 ms |
8960 KB |
Output is correct |
10 |
Correct |
13 ms |
8960 KB |
Output is correct |
11 |
Correct |
9 ms |
8960 KB |
Output is correct |
12 |
Correct |
11 ms |
8960 KB |
Output is correct |
13 |
Correct |
10 ms |
8960 KB |
Output is correct |
14 |
Correct |
14 ms |
8960 KB |
Output is correct |
15 |
Correct |
10 ms |
8960 KB |
Output is correct |
16 |
Correct |
10 ms |
8960 KB |
Output is correct |
17 |
Correct |
11 ms |
8980 KB |
Output is correct |
18 |
Correct |
12 ms |
8960 KB |
Output is correct |
19 |
Correct |
12 ms |
8960 KB |
Output is correct |
20 |
Correct |
9 ms |
8892 KB |
Output is correct |
21 |
Correct |
10 ms |
9088 KB |
Output is correct |
22 |
Correct |
11 ms |
9088 KB |
Output is correct |
23 |
Correct |
12 ms |
8960 KB |
Output is correct |
24 |
Correct |
10 ms |
8960 KB |
Output is correct |
25 |
Correct |
11 ms |
8960 KB |
Output is correct |
26 |
Correct |
12 ms |
9216 KB |
Output is correct |
27 |
Correct |
11 ms |
8960 KB |
Output is correct |
28 |
Correct |
12 ms |
8960 KB |
Output is correct |
29 |
Correct |
13 ms |
8948 KB |
Output is correct |
30 |
Correct |
12 ms |
9088 KB |
Output is correct |
31 |
Correct |
10 ms |
8960 KB |
Output is correct |
32 |
Correct |
12 ms |
9088 KB |
Output is correct |
33 |
Correct |
12 ms |
9100 KB |
Output is correct |
34 |
Correct |
11 ms |
9088 KB |
Output is correct |
35 |
Correct |
13 ms |
8960 KB |
Output is correct |
36 |
Correct |
11 ms |
8960 KB |
Output is correct |
37 |
Correct |
12 ms |
9020 KB |
Output is correct |
38 |
Correct |
11 ms |
8960 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
8960 KB |
Output is correct |
2 |
Correct |
10 ms |
8960 KB |
Output is correct |
3 |
Correct |
8 ms |
8960 KB |
Output is correct |
4 |
Correct |
11 ms |
8960 KB |
Output is correct |
5 |
Correct |
9 ms |
8948 KB |
Output is correct |
6 |
Correct |
10 ms |
8960 KB |
Output is correct |
7 |
Correct |
10 ms |
9008 KB |
Output is correct |
8 |
Correct |
10 ms |
8960 KB |
Output is correct |
9 |
Correct |
11 ms |
8960 KB |
Output is correct |
10 |
Correct |
13 ms |
8960 KB |
Output is correct |
11 |
Correct |
9 ms |
8960 KB |
Output is correct |
12 |
Correct |
11 ms |
8960 KB |
Output is correct |
13 |
Correct |
10 ms |
8960 KB |
Output is correct |
14 |
Correct |
14 ms |
8960 KB |
Output is correct |
15 |
Correct |
10 ms |
8960 KB |
Output is correct |
16 |
Correct |
10 ms |
8960 KB |
Output is correct |
17 |
Correct |
11 ms |
8980 KB |
Output is correct |
18 |
Correct |
12 ms |
8960 KB |
Output is correct |
19 |
Correct |
203 ms |
14760 KB |
Output is correct |
20 |
Correct |
194 ms |
15836 KB |
Output is correct |
21 |
Correct |
188 ms |
16152 KB |
Output is correct |
22 |
Correct |
196 ms |
16708 KB |
Output is correct |
23 |
Correct |
177 ms |
16164 KB |
Output is correct |
24 |
Correct |
111 ms |
15864 KB |
Output is correct |
25 |
Correct |
227 ms |
18552 KB |
Output is correct |
26 |
Correct |
160 ms |
22812 KB |
Output is correct |
27 |
Correct |
283 ms |
22872 KB |
Output is correct |
28 |
Correct |
603 ms |
34180 KB |
Output is correct |
29 |
Correct |
533 ms |
33144 KB |
Output is correct |
30 |
Correct |
260 ms |
22900 KB |
Output is correct |
31 |
Correct |
251 ms |
22776 KB |
Output is correct |
32 |
Correct |
313 ms |
22904 KB |
Output is correct |
33 |
Correct |
434 ms |
21780 KB |
Output is correct |
34 |
Correct |
380 ms |
22708 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
8960 KB |
Output is correct |
2 |
Correct |
10 ms |
8960 KB |
Output is correct |
3 |
Correct |
8 ms |
8960 KB |
Output is correct |
4 |
Correct |
11 ms |
8960 KB |
Output is correct |
5 |
Correct |
9 ms |
8948 KB |
Output is correct |
6 |
Correct |
10 ms |
8960 KB |
Output is correct |
7 |
Correct |
10 ms |
9008 KB |
Output is correct |
8 |
Correct |
10 ms |
8960 KB |
Output is correct |
9 |
Correct |
11 ms |
8960 KB |
Output is correct |
10 |
Correct |
13 ms |
8960 KB |
Output is correct |
11 |
Correct |
9 ms |
8960 KB |
Output is correct |
12 |
Correct |
11 ms |
8960 KB |
Output is correct |
13 |
Correct |
10 ms |
8960 KB |
Output is correct |
14 |
Correct |
14 ms |
8960 KB |
Output is correct |
15 |
Correct |
10 ms |
8960 KB |
Output is correct |
16 |
Correct |
10 ms |
8960 KB |
Output is correct |
17 |
Correct |
11 ms |
8980 KB |
Output is correct |
18 |
Correct |
12 ms |
8960 KB |
Output is correct |
19 |
Correct |
12 ms |
8960 KB |
Output is correct |
20 |
Correct |
9 ms |
8892 KB |
Output is correct |
21 |
Correct |
10 ms |
9088 KB |
Output is correct |
22 |
Correct |
11 ms |
9088 KB |
Output is correct |
23 |
Correct |
12 ms |
8960 KB |
Output is correct |
24 |
Correct |
10 ms |
8960 KB |
Output is correct |
25 |
Correct |
11 ms |
8960 KB |
Output is correct |
26 |
Correct |
12 ms |
9216 KB |
Output is correct |
27 |
Correct |
11 ms |
8960 KB |
Output is correct |
28 |
Correct |
12 ms |
8960 KB |
Output is correct |
29 |
Correct |
13 ms |
8948 KB |
Output is correct |
30 |
Correct |
12 ms |
9088 KB |
Output is correct |
31 |
Correct |
10 ms |
8960 KB |
Output is correct |
32 |
Correct |
12 ms |
9088 KB |
Output is correct |
33 |
Correct |
12 ms |
9100 KB |
Output is correct |
34 |
Correct |
11 ms |
9088 KB |
Output is correct |
35 |
Correct |
13 ms |
8960 KB |
Output is correct |
36 |
Correct |
11 ms |
8960 KB |
Output is correct |
37 |
Correct |
12 ms |
9020 KB |
Output is correct |
38 |
Correct |
11 ms |
8960 KB |
Output is correct |
39 |
Correct |
203 ms |
14760 KB |
Output is correct |
40 |
Correct |
194 ms |
15836 KB |
Output is correct |
41 |
Correct |
188 ms |
16152 KB |
Output is correct |
42 |
Correct |
196 ms |
16708 KB |
Output is correct |
43 |
Correct |
177 ms |
16164 KB |
Output is correct |
44 |
Correct |
111 ms |
15864 KB |
Output is correct |
45 |
Correct |
227 ms |
18552 KB |
Output is correct |
46 |
Correct |
160 ms |
22812 KB |
Output is correct |
47 |
Correct |
283 ms |
22872 KB |
Output is correct |
48 |
Correct |
603 ms |
34180 KB |
Output is correct |
49 |
Correct |
533 ms |
33144 KB |
Output is correct |
50 |
Correct |
260 ms |
22900 KB |
Output is correct |
51 |
Correct |
251 ms |
22776 KB |
Output is correct |
52 |
Correct |
313 ms |
22904 KB |
Output is correct |
53 |
Correct |
434 ms |
21780 KB |
Output is correct |
54 |
Correct |
380 ms |
22708 KB |
Output is correct |
55 |
Correct |
20 ms |
9728 KB |
Output is correct |
56 |
Correct |
23 ms |
9728 KB |
Output is correct |
57 |
Correct |
93 ms |
16856 KB |
Output is correct |
58 |
Correct |
51 ms |
16592 KB |
Output is correct |
59 |
Correct |
140 ms |
22612 KB |
Output is correct |
60 |
Correct |
819 ms |
36156 KB |
Output is correct |
61 |
Correct |
269 ms |
23124 KB |
Output is correct |
62 |
Correct |
375 ms |
23904 KB |
Output is correct |
63 |
Correct |
367 ms |
23936 KB |
Output is correct |
64 |
Correct |
767 ms |
25452 KB |
Output is correct |
65 |
Correct |
364 ms |
23672 KB |
Output is correct |
66 |
Correct |
621 ms |
31480 KB |
Output is correct |
67 |
Correct |
191 ms |
25272 KB |
Output is correct |
68 |
Correct |
387 ms |
24816 KB |
Output is correct |
69 |
Correct |
397 ms |
25032 KB |
Output is correct |
70 |
Correct |
387 ms |
24148 KB |
Output is correct |