# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
315636 |
2020-10-23T13:01:55 Z |
ivan_tudor |
Race (IOI11_race) |
C++14 |
|
1621 ms |
46712 KB |
#include "race.h"
#include <bits/stdc++.h>
using namespace std;
const int N = 200005;
int n,k;
int ANS;
struct muchii{
int x;
int d;
};
vector<muchii> gr[N];
int sz[N];
bool iscentr[N];
void dfs_sz(int nod,int dad){
sz[nod] = 1;
for(auto f:gr[nod]){
if(f.x != dad && iscentr[f.x] == 0){
dfs_sz(f.x,nod);
sz[nod] += sz[f.x];
}
}
}
int findcentr(int nod,int dad, int bigroot){
for(auto f:gr[nod]){
if(f.x != dad && iscentr[f.x] == 0 && sz[f.x] > sz[bigroot]/2)
return findcentr(f.x, nod, bigroot);
}
return nod;
}
void build_dfs(int nod,int dad,int distkm,int dst, map<int,int> &cur){
if(distkm > k)
return;
if(cur.count(distkm))
cur[distkm] = min(cur[distkm], dst);
else
cur[distkm] = dst;
for(auto f:gr[nod]){
if(f.x != dad && iscentr[f.x] == 0){
build_dfs(f.x, nod, distkm + f.d, dst + 1, cur);
}
}
}
void buildcentr(int root){
dfs_sz(root, 0);
int cen = findcentr(root, 0, root);
map<int,int> ansc;
for(auto f:gr[cen]){
if(iscentr[f.x] == 0){
map<int,int> cur;
build_dfs(f.x, cen, f.d, 1, cur);
for(auto x:cur){
if(ansc.count(k - x.first)){
ANS = min(ANS, x.second + ansc[k - x.first]);
}
}
for(auto x:cur){
if(ansc.count(x.first))
ansc[x.first] = min(ansc[x.first], x.second);
else
ansc[x.first] = x.second;
}
}
}
if(ansc.count(k))
ANS = min(ANS, ansc[k]);
iscentr[cen] = true;
for(auto f: gr[cen]){
if(iscentr[f.x] == 0)
buildcentr(f.x);
}
}
int best_path(int _n, int _k, int H[][2], int L[])
{
k = _k;
n = _n;
for(int i=0;i<n-1;i++){
int x, y;
x = H[i][0] + 1;
y = H[i][1] + 1;
gr[x].push_back({y,L[i]});
gr[y].push_back({x,L[i]});
}
ANS = INT_MAX;
buildcentr(1);
if(ANS == INT_MAX)
return -1;
return ANS;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
4992 KB |
Output is correct |
2 |
Correct |
4 ms |
4992 KB |
Output is correct |
3 |
Correct |
4 ms |
4992 KB |
Output is correct |
4 |
Correct |
4 ms |
4992 KB |
Output is correct |
5 |
Correct |
4 ms |
4992 KB |
Output is correct |
6 |
Correct |
4 ms |
4992 KB |
Output is correct |
7 |
Correct |
4 ms |
4992 KB |
Output is correct |
8 |
Correct |
4 ms |
4992 KB |
Output is correct |
9 |
Correct |
4 ms |
4992 KB |
Output is correct |
10 |
Correct |
4 ms |
4992 KB |
Output is correct |
11 |
Correct |
4 ms |
4992 KB |
Output is correct |
12 |
Correct |
4 ms |
4992 KB |
Output is correct |
13 |
Correct |
5 ms |
4992 KB |
Output is correct |
14 |
Correct |
4 ms |
4992 KB |
Output is correct |
15 |
Correct |
4 ms |
4992 KB |
Output is correct |
16 |
Correct |
4 ms |
4992 KB |
Output is correct |
17 |
Correct |
4 ms |
4992 KB |
Output is correct |
18 |
Correct |
4 ms |
4992 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
4992 KB |
Output is correct |
2 |
Correct |
4 ms |
4992 KB |
Output is correct |
3 |
Correct |
4 ms |
4992 KB |
Output is correct |
4 |
Correct |
4 ms |
4992 KB |
Output is correct |
5 |
Correct |
4 ms |
4992 KB |
Output is correct |
6 |
Correct |
4 ms |
4992 KB |
Output is correct |
7 |
Correct |
4 ms |
4992 KB |
Output is correct |
8 |
Correct |
4 ms |
4992 KB |
Output is correct |
9 |
Correct |
4 ms |
4992 KB |
Output is correct |
10 |
Correct |
4 ms |
4992 KB |
Output is correct |
11 |
Correct |
4 ms |
4992 KB |
Output is correct |
12 |
Correct |
4 ms |
4992 KB |
Output is correct |
13 |
Correct |
5 ms |
4992 KB |
Output is correct |
14 |
Correct |
4 ms |
4992 KB |
Output is correct |
15 |
Correct |
4 ms |
4992 KB |
Output is correct |
16 |
Correct |
4 ms |
4992 KB |
Output is correct |
17 |
Correct |
4 ms |
4992 KB |
Output is correct |
18 |
Correct |
4 ms |
4992 KB |
Output is correct |
19 |
Correct |
4 ms |
4992 KB |
Output is correct |
20 |
Correct |
4 ms |
4992 KB |
Output is correct |
21 |
Correct |
6 ms |
5120 KB |
Output is correct |
22 |
Correct |
5 ms |
5120 KB |
Output is correct |
23 |
Correct |
5 ms |
5248 KB |
Output is correct |
24 |
Correct |
5 ms |
5120 KB |
Output is correct |
25 |
Correct |
6 ms |
5120 KB |
Output is correct |
26 |
Correct |
5 ms |
5120 KB |
Output is correct |
27 |
Correct |
4 ms |
5120 KB |
Output is correct |
28 |
Correct |
6 ms |
5120 KB |
Output is correct |
29 |
Correct |
6 ms |
5120 KB |
Output is correct |
30 |
Correct |
6 ms |
5248 KB |
Output is correct |
31 |
Correct |
6 ms |
5248 KB |
Output is correct |
32 |
Correct |
7 ms |
5248 KB |
Output is correct |
33 |
Correct |
8 ms |
5248 KB |
Output is correct |
34 |
Correct |
5 ms |
5120 KB |
Output is correct |
35 |
Correct |
5 ms |
5120 KB |
Output is correct |
36 |
Correct |
5 ms |
5120 KB |
Output is correct |
37 |
Correct |
6 ms |
5248 KB |
Output is correct |
38 |
Correct |
6 ms |
5120 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
4992 KB |
Output is correct |
2 |
Correct |
4 ms |
4992 KB |
Output is correct |
3 |
Correct |
4 ms |
4992 KB |
Output is correct |
4 |
Correct |
4 ms |
4992 KB |
Output is correct |
5 |
Correct |
4 ms |
4992 KB |
Output is correct |
6 |
Correct |
4 ms |
4992 KB |
Output is correct |
7 |
Correct |
4 ms |
4992 KB |
Output is correct |
8 |
Correct |
4 ms |
4992 KB |
Output is correct |
9 |
Correct |
4 ms |
4992 KB |
Output is correct |
10 |
Correct |
4 ms |
4992 KB |
Output is correct |
11 |
Correct |
4 ms |
4992 KB |
Output is correct |
12 |
Correct |
4 ms |
4992 KB |
Output is correct |
13 |
Correct |
5 ms |
4992 KB |
Output is correct |
14 |
Correct |
4 ms |
4992 KB |
Output is correct |
15 |
Correct |
4 ms |
4992 KB |
Output is correct |
16 |
Correct |
4 ms |
4992 KB |
Output is correct |
17 |
Correct |
4 ms |
4992 KB |
Output is correct |
18 |
Correct |
4 ms |
4992 KB |
Output is correct |
19 |
Correct |
290 ms |
11896 KB |
Output is correct |
20 |
Correct |
293 ms |
11896 KB |
Output is correct |
21 |
Correct |
302 ms |
11768 KB |
Output is correct |
22 |
Correct |
281 ms |
11896 KB |
Output is correct |
23 |
Correct |
127 ms |
12028 KB |
Output is correct |
24 |
Correct |
118 ms |
12024 KB |
Output is correct |
25 |
Correct |
197 ms |
14580 KB |
Output is correct |
26 |
Correct |
119 ms |
17400 KB |
Output is correct |
27 |
Correct |
321 ms |
18884 KB |
Output is correct |
28 |
Correct |
380 ms |
30200 KB |
Output is correct |
29 |
Correct |
389 ms |
29432 KB |
Output is correct |
30 |
Correct |
311 ms |
18808 KB |
Output is correct |
31 |
Correct |
311 ms |
19064 KB |
Output is correct |
32 |
Correct |
340 ms |
19064 KB |
Output is correct |
33 |
Correct |
518 ms |
17912 KB |
Output is correct |
34 |
Correct |
259 ms |
18628 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
4992 KB |
Output is correct |
2 |
Correct |
4 ms |
4992 KB |
Output is correct |
3 |
Correct |
4 ms |
4992 KB |
Output is correct |
4 |
Correct |
4 ms |
4992 KB |
Output is correct |
5 |
Correct |
4 ms |
4992 KB |
Output is correct |
6 |
Correct |
4 ms |
4992 KB |
Output is correct |
7 |
Correct |
4 ms |
4992 KB |
Output is correct |
8 |
Correct |
4 ms |
4992 KB |
Output is correct |
9 |
Correct |
4 ms |
4992 KB |
Output is correct |
10 |
Correct |
4 ms |
4992 KB |
Output is correct |
11 |
Correct |
4 ms |
4992 KB |
Output is correct |
12 |
Correct |
4 ms |
4992 KB |
Output is correct |
13 |
Correct |
5 ms |
4992 KB |
Output is correct |
14 |
Correct |
4 ms |
4992 KB |
Output is correct |
15 |
Correct |
4 ms |
4992 KB |
Output is correct |
16 |
Correct |
4 ms |
4992 KB |
Output is correct |
17 |
Correct |
4 ms |
4992 KB |
Output is correct |
18 |
Correct |
4 ms |
4992 KB |
Output is correct |
19 |
Correct |
4 ms |
4992 KB |
Output is correct |
20 |
Correct |
4 ms |
4992 KB |
Output is correct |
21 |
Correct |
6 ms |
5120 KB |
Output is correct |
22 |
Correct |
5 ms |
5120 KB |
Output is correct |
23 |
Correct |
5 ms |
5248 KB |
Output is correct |
24 |
Correct |
5 ms |
5120 KB |
Output is correct |
25 |
Correct |
6 ms |
5120 KB |
Output is correct |
26 |
Correct |
5 ms |
5120 KB |
Output is correct |
27 |
Correct |
4 ms |
5120 KB |
Output is correct |
28 |
Correct |
6 ms |
5120 KB |
Output is correct |
29 |
Correct |
6 ms |
5120 KB |
Output is correct |
30 |
Correct |
6 ms |
5248 KB |
Output is correct |
31 |
Correct |
6 ms |
5248 KB |
Output is correct |
32 |
Correct |
7 ms |
5248 KB |
Output is correct |
33 |
Correct |
8 ms |
5248 KB |
Output is correct |
34 |
Correct |
5 ms |
5120 KB |
Output is correct |
35 |
Correct |
5 ms |
5120 KB |
Output is correct |
36 |
Correct |
5 ms |
5120 KB |
Output is correct |
37 |
Correct |
6 ms |
5248 KB |
Output is correct |
38 |
Correct |
6 ms |
5120 KB |
Output is correct |
39 |
Correct |
290 ms |
11896 KB |
Output is correct |
40 |
Correct |
293 ms |
11896 KB |
Output is correct |
41 |
Correct |
302 ms |
11768 KB |
Output is correct |
42 |
Correct |
281 ms |
11896 KB |
Output is correct |
43 |
Correct |
127 ms |
12028 KB |
Output is correct |
44 |
Correct |
118 ms |
12024 KB |
Output is correct |
45 |
Correct |
197 ms |
14580 KB |
Output is correct |
46 |
Correct |
119 ms |
17400 KB |
Output is correct |
47 |
Correct |
321 ms |
18884 KB |
Output is correct |
48 |
Correct |
380 ms |
30200 KB |
Output is correct |
49 |
Correct |
389 ms |
29432 KB |
Output is correct |
50 |
Correct |
311 ms |
18808 KB |
Output is correct |
51 |
Correct |
311 ms |
19064 KB |
Output is correct |
52 |
Correct |
340 ms |
19064 KB |
Output is correct |
53 |
Correct |
518 ms |
17912 KB |
Output is correct |
54 |
Correct |
259 ms |
18628 KB |
Output is correct |
55 |
Correct |
32 ms |
6016 KB |
Output is correct |
56 |
Correct |
21 ms |
5632 KB |
Output is correct |
57 |
Correct |
182 ms |
11896 KB |
Output is correct |
58 |
Correct |
65 ms |
11628 KB |
Output is correct |
59 |
Correct |
554 ms |
24648 KB |
Output is correct |
60 |
Correct |
1621 ms |
46712 KB |
Output is correct |
61 |
Correct |
423 ms |
19192 KB |
Output is correct |
62 |
Correct |
479 ms |
19192 KB |
Output is correct |
63 |
Correct |
551 ms |
19192 KB |
Output is correct |
64 |
Correct |
1613 ms |
30260 KB |
Output is correct |
65 |
Correct |
328 ms |
19832 KB |
Output is correct |
66 |
Correct |
1061 ms |
28920 KB |
Output is correct |
67 |
Correct |
202 ms |
19556 KB |
Output is correct |
68 |
Correct |
617 ms |
26744 KB |
Output is correct |
69 |
Correct |
622 ms |
26744 KB |
Output is correct |
70 |
Correct |
593 ms |
25848 KB |
Output is correct |