# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
486783 |
2021-11-12T19:11:00 Z |
status_coding |
Race (IOI11_race) |
C++14 |
|
382 ms |
89296 KB |
#include <bits/stdc++.h>
using namespace std;
struct mulS
{
map<int, int> m;
int dif=0;
mulS(){};
mulS(int d)
{
m[0]=d;
}
};
struct nodS
{
int d;
mulS *mul;
vector<pair<int, int>> v;
};
int n,k,ans;
nodS nod[200005];
int getVal(mulS *a, int val)
{
val -= a->dif;
if(a->m.find(val) == a->m.end())
return -1;
return a->m[val];
}
void mergeMul(int d, mulS *&a, mulS *& b)
{
if(a->m.size() < b->m.size())
swap(a, b);
for(auto it : b->m)
{
int trVal = it.first + b->dif;
int oD = getVal(a, k - trVal);
if(oD != -1)
ans = min(ans, it.second + oD - 2*d);
}
for(auto it : b->m)
{
int nVal = it.first + b->dif - a->dif;
if(a->m.find(nVal) == a->m.end() || a->m[nVal] > it.second)
a->m[nVal] = it.second;
}
}
void dfs(int p, int par)
{
nod[p].d = nod[par].d+1;
nod[p].mul = new mulS(nod[p].d);
for(auto it : nod[p].v)
{
if(it.first == par)
continue;
dfs(it.first, p);
nod[it.first].mul->dif += it.second;
mergeMul(nod[p].d, nod[p].mul, nod[it.first].mul);
}
/*
if(p >= 9)
{
cout<<p<<":\n";
for(auto it : nod[p].mul->m)
cout<<it.first + nod[p].mul->dif<<' '<<it.second<<'\n';
cout<<'\n';
}
*/
}
int best_path(int N, int K, int h[][2], int l[])
{
n=N;
k=K;
for(int i=0;i<n-1;i++)
{
int x = h[i][0] + 1;
int y = h[i][1] + 1;
nod[x].v.push_back({y, l[i]});
nod[y].v.push_back({x, l[i]});
}
ans=1e9;
dfs(1, 0);
if(ans == 1e9)
return -1;
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
8140 KB |
Output is correct |
2 |
Correct |
4 ms |
8140 KB |
Output is correct |
3 |
Correct |
4 ms |
8140 KB |
Output is correct |
4 |
Correct |
5 ms |
8124 KB |
Output is correct |
5 |
Correct |
4 ms |
8140 KB |
Output is correct |
6 |
Correct |
3 ms |
8140 KB |
Output is correct |
7 |
Correct |
4 ms |
8140 KB |
Output is correct |
8 |
Correct |
4 ms |
8132 KB |
Output is correct |
9 |
Correct |
4 ms |
8140 KB |
Output is correct |
10 |
Correct |
4 ms |
8140 KB |
Output is correct |
11 |
Correct |
5 ms |
8140 KB |
Output is correct |
12 |
Correct |
4 ms |
8140 KB |
Output is correct |
13 |
Correct |
4 ms |
8140 KB |
Output is correct |
14 |
Correct |
4 ms |
8140 KB |
Output is correct |
15 |
Correct |
4 ms |
8140 KB |
Output is correct |
16 |
Correct |
4 ms |
8140 KB |
Output is correct |
17 |
Correct |
4 ms |
8092 KB |
Output is correct |
18 |
Correct |
5 ms |
8140 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
8140 KB |
Output is correct |
2 |
Correct |
4 ms |
8140 KB |
Output is correct |
3 |
Correct |
4 ms |
8140 KB |
Output is correct |
4 |
Correct |
5 ms |
8124 KB |
Output is correct |
5 |
Correct |
4 ms |
8140 KB |
Output is correct |
6 |
Correct |
3 ms |
8140 KB |
Output is correct |
7 |
Correct |
4 ms |
8140 KB |
Output is correct |
8 |
Correct |
4 ms |
8132 KB |
Output is correct |
9 |
Correct |
4 ms |
8140 KB |
Output is correct |
10 |
Correct |
4 ms |
8140 KB |
Output is correct |
11 |
Correct |
5 ms |
8140 KB |
Output is correct |
12 |
Correct |
4 ms |
8140 KB |
Output is correct |
13 |
Correct |
4 ms |
8140 KB |
Output is correct |
14 |
Correct |
4 ms |
8140 KB |
Output is correct |
15 |
Correct |
4 ms |
8140 KB |
Output is correct |
16 |
Correct |
4 ms |
8140 KB |
Output is correct |
17 |
Correct |
4 ms |
8092 KB |
Output is correct |
18 |
Correct |
5 ms |
8140 KB |
Output is correct |
19 |
Correct |
5 ms |
8036 KB |
Output is correct |
20 |
Correct |
4 ms |
8140 KB |
Output is correct |
21 |
Correct |
6 ms |
8396 KB |
Output is correct |
22 |
Correct |
5 ms |
8396 KB |
Output is correct |
23 |
Correct |
4 ms |
8396 KB |
Output is correct |
24 |
Correct |
5 ms |
8396 KB |
Output is correct |
25 |
Correct |
5 ms |
8392 KB |
Output is correct |
26 |
Correct |
5 ms |
8396 KB |
Output is correct |
27 |
Correct |
6 ms |
8264 KB |
Output is correct |
28 |
Correct |
5 ms |
8396 KB |
Output is correct |
29 |
Correct |
5 ms |
8396 KB |
Output is correct |
30 |
Correct |
5 ms |
8376 KB |
Output is correct |
31 |
Correct |
6 ms |
8396 KB |
Output is correct |
32 |
Correct |
5 ms |
8396 KB |
Output is correct |
33 |
Correct |
5 ms |
8396 KB |
Output is correct |
34 |
Correct |
4 ms |
8268 KB |
Output is correct |
35 |
Correct |
4 ms |
8268 KB |
Output is correct |
36 |
Correct |
4 ms |
8268 KB |
Output is correct |
37 |
Correct |
4 ms |
8364 KB |
Output is correct |
38 |
Correct |
5 ms |
8392 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
8140 KB |
Output is correct |
2 |
Correct |
4 ms |
8140 KB |
Output is correct |
3 |
Correct |
4 ms |
8140 KB |
Output is correct |
4 |
Correct |
5 ms |
8124 KB |
Output is correct |
5 |
Correct |
4 ms |
8140 KB |
Output is correct |
6 |
Correct |
3 ms |
8140 KB |
Output is correct |
7 |
Correct |
4 ms |
8140 KB |
Output is correct |
8 |
Correct |
4 ms |
8132 KB |
Output is correct |
9 |
Correct |
4 ms |
8140 KB |
Output is correct |
10 |
Correct |
4 ms |
8140 KB |
Output is correct |
11 |
Correct |
5 ms |
8140 KB |
Output is correct |
12 |
Correct |
4 ms |
8140 KB |
Output is correct |
13 |
Correct |
4 ms |
8140 KB |
Output is correct |
14 |
Correct |
4 ms |
8140 KB |
Output is correct |
15 |
Correct |
4 ms |
8140 KB |
Output is correct |
16 |
Correct |
4 ms |
8140 KB |
Output is correct |
17 |
Correct |
4 ms |
8092 KB |
Output is correct |
18 |
Correct |
5 ms |
8140 KB |
Output is correct |
19 |
Correct |
92 ms |
32180 KB |
Output is correct |
20 |
Correct |
94 ms |
32184 KB |
Output is correct |
21 |
Correct |
90 ms |
31988 KB |
Output is correct |
22 |
Correct |
95 ms |
31808 KB |
Output is correct |
23 |
Correct |
122 ms |
41412 KB |
Output is correct |
24 |
Correct |
95 ms |
34312 KB |
Output is correct |
25 |
Correct |
80 ms |
30352 KB |
Output is correct |
26 |
Correct |
58 ms |
34080 KB |
Output is correct |
27 |
Correct |
167 ms |
47668 KB |
Output is correct |
28 |
Correct |
229 ms |
69952 KB |
Output is correct |
29 |
Correct |
224 ms |
69272 KB |
Output is correct |
30 |
Correct |
170 ms |
47588 KB |
Output is correct |
31 |
Correct |
170 ms |
47640 KB |
Output is correct |
32 |
Correct |
184 ms |
47780 KB |
Output is correct |
33 |
Correct |
174 ms |
50884 KB |
Output is correct |
34 |
Correct |
258 ms |
75764 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
8140 KB |
Output is correct |
2 |
Correct |
4 ms |
8140 KB |
Output is correct |
3 |
Correct |
4 ms |
8140 KB |
Output is correct |
4 |
Correct |
5 ms |
8124 KB |
Output is correct |
5 |
Correct |
4 ms |
8140 KB |
Output is correct |
6 |
Correct |
3 ms |
8140 KB |
Output is correct |
7 |
Correct |
4 ms |
8140 KB |
Output is correct |
8 |
Correct |
4 ms |
8132 KB |
Output is correct |
9 |
Correct |
4 ms |
8140 KB |
Output is correct |
10 |
Correct |
4 ms |
8140 KB |
Output is correct |
11 |
Correct |
5 ms |
8140 KB |
Output is correct |
12 |
Correct |
4 ms |
8140 KB |
Output is correct |
13 |
Correct |
4 ms |
8140 KB |
Output is correct |
14 |
Correct |
4 ms |
8140 KB |
Output is correct |
15 |
Correct |
4 ms |
8140 KB |
Output is correct |
16 |
Correct |
4 ms |
8140 KB |
Output is correct |
17 |
Correct |
4 ms |
8092 KB |
Output is correct |
18 |
Correct |
5 ms |
8140 KB |
Output is correct |
19 |
Correct |
5 ms |
8036 KB |
Output is correct |
20 |
Correct |
4 ms |
8140 KB |
Output is correct |
21 |
Correct |
6 ms |
8396 KB |
Output is correct |
22 |
Correct |
5 ms |
8396 KB |
Output is correct |
23 |
Correct |
4 ms |
8396 KB |
Output is correct |
24 |
Correct |
5 ms |
8396 KB |
Output is correct |
25 |
Correct |
5 ms |
8392 KB |
Output is correct |
26 |
Correct |
5 ms |
8396 KB |
Output is correct |
27 |
Correct |
6 ms |
8264 KB |
Output is correct |
28 |
Correct |
5 ms |
8396 KB |
Output is correct |
29 |
Correct |
5 ms |
8396 KB |
Output is correct |
30 |
Correct |
5 ms |
8376 KB |
Output is correct |
31 |
Correct |
6 ms |
8396 KB |
Output is correct |
32 |
Correct |
5 ms |
8396 KB |
Output is correct |
33 |
Correct |
5 ms |
8396 KB |
Output is correct |
34 |
Correct |
4 ms |
8268 KB |
Output is correct |
35 |
Correct |
4 ms |
8268 KB |
Output is correct |
36 |
Correct |
4 ms |
8268 KB |
Output is correct |
37 |
Correct |
4 ms |
8364 KB |
Output is correct |
38 |
Correct |
5 ms |
8392 KB |
Output is correct |
39 |
Correct |
92 ms |
32180 KB |
Output is correct |
40 |
Correct |
94 ms |
32184 KB |
Output is correct |
41 |
Correct |
90 ms |
31988 KB |
Output is correct |
42 |
Correct |
95 ms |
31808 KB |
Output is correct |
43 |
Correct |
122 ms |
41412 KB |
Output is correct |
44 |
Correct |
95 ms |
34312 KB |
Output is correct |
45 |
Correct |
80 ms |
30352 KB |
Output is correct |
46 |
Correct |
58 ms |
34080 KB |
Output is correct |
47 |
Correct |
167 ms |
47668 KB |
Output is correct |
48 |
Correct |
229 ms |
69952 KB |
Output is correct |
49 |
Correct |
224 ms |
69272 KB |
Output is correct |
50 |
Correct |
170 ms |
47588 KB |
Output is correct |
51 |
Correct |
170 ms |
47640 KB |
Output is correct |
52 |
Correct |
184 ms |
47780 KB |
Output is correct |
53 |
Correct |
174 ms |
50884 KB |
Output is correct |
54 |
Correct |
258 ms |
75764 KB |
Output is correct |
55 |
Correct |
17 ms |
11196 KB |
Output is correct |
56 |
Correct |
10 ms |
10188 KB |
Output is correct |
57 |
Correct |
61 ms |
30348 KB |
Output is correct |
58 |
Correct |
48 ms |
25188 KB |
Output is correct |
59 |
Correct |
85 ms |
38740 KB |
Output is correct |
60 |
Correct |
208 ms |
69096 KB |
Output is correct |
61 |
Correct |
194 ms |
50352 KB |
Output is correct |
62 |
Correct |
163 ms |
47612 KB |
Output is correct |
63 |
Correct |
188 ms |
47760 KB |
Output is correct |
64 |
Correct |
382 ms |
89296 KB |
Output is correct |
65 |
Correct |
362 ms |
87968 KB |
Output is correct |
66 |
Correct |
244 ms |
67652 KB |
Output is correct |
67 |
Correct |
133 ms |
43804 KB |
Output is correct |
68 |
Correct |
252 ms |
60408 KB |
Output is correct |
69 |
Correct |
277 ms |
64372 KB |
Output is correct |
70 |
Correct |
234 ms |
58180 KB |
Output is correct |