# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1112058 |
2024-11-13T15:20:42 Z |
FucKanh |
Race (IOI11_race) |
C++14 |
|
128 ms |
72008 KB |
#include <bits/stdc++.h>
#include <race.h>
#define ll long long
#define pii pair<long long,long long>
using namespace std;
const ll maxn = 5e5 + 2;
ll sz[maxn],h[maxn],k;
vector<pii> a[maxn];
ll ans = LLONG_MAX;
map<ll,ll> mp[maxn];
void dfs(ll u, ll w, ll pa) {
assert(h[u]!=0);
for (pii tmp : a[u]) {
ll wv,v; tie(v,wv) = tmp;
if (v==pa) continue;
h[v] = h[u] + 1;
dfs(v,w+wv,u);
mp[v][w+wv] = h[v];
if (mp[u].size() < mp[v].size()) swap(mp[u],mp[v]);
for (pii val : mp[v]) {
if (val.second==0) continue;
if (val.first - w < k && mp[u][k-val.first+2*w] != 0) {
ans = min(ans, mp[u][k-val.first+2*w] - h[u] + val.second - h[u]);
}
}
mp[u].insert(mp[v].begin(),mp[v].end());
if (mp[u][w + k] != 0) {
ans = min(ans, mp[u][w+k]-h[u]);
}
}
}
int best_path(int _n, int _k, int _h[][2], int _L[])
{
k = _k;
for (ll i = 0; i < _n - 1; i++){
ll x = _h[i][0], y = _h[i][1];
ll w = _L[i];
a[x].push_back({y,w});
a[y].push_back({x,w});
}
h[0] = 1;
dfs(0,0,-1);
assert(ans > 0);
return ans == LLONG_MAX ? -1 : ans;
}
//signed main() {
// int N = 11, K = 12;
// int H[10][2] = {
// {0,1},
// {0,2},
// {0,8},
// {1,3},
// {3,7},
// {2,4},
// {0,5},
// {5,6},
// {8,9},
// {9,10},
// };
// int L[10] = {1,1,1,2,3,2,1,2,2,3};
// cout << best_path(N,K,H,L);
//}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
39380 KB |
Output is correct |
2 |
Correct |
6 ms |
39392 KB |
Output is correct |
3 |
Correct |
7 ms |
39248 KB |
Output is correct |
4 |
Correct |
7 ms |
39248 KB |
Output is correct |
5 |
Correct |
6 ms |
39464 KB |
Output is correct |
6 |
Correct |
7 ms |
39248 KB |
Output is correct |
7 |
Correct |
7 ms |
39248 KB |
Output is correct |
8 |
Correct |
7 ms |
39248 KB |
Output is correct |
9 |
Correct |
6 ms |
39248 KB |
Output is correct |
10 |
Correct |
6 ms |
39416 KB |
Output is correct |
11 |
Correct |
7 ms |
39248 KB |
Output is correct |
12 |
Correct |
7 ms |
39248 KB |
Output is correct |
13 |
Correct |
9 ms |
39428 KB |
Output is correct |
14 |
Correct |
7 ms |
39248 KB |
Output is correct |
15 |
Correct |
6 ms |
39248 KB |
Output is correct |
16 |
Correct |
7 ms |
39248 KB |
Output is correct |
17 |
Correct |
7 ms |
39416 KB |
Output is correct |
18 |
Correct |
7 ms |
39452 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
39380 KB |
Output is correct |
2 |
Correct |
6 ms |
39392 KB |
Output is correct |
3 |
Correct |
7 ms |
39248 KB |
Output is correct |
4 |
Correct |
7 ms |
39248 KB |
Output is correct |
5 |
Correct |
6 ms |
39464 KB |
Output is correct |
6 |
Correct |
7 ms |
39248 KB |
Output is correct |
7 |
Correct |
7 ms |
39248 KB |
Output is correct |
8 |
Correct |
7 ms |
39248 KB |
Output is correct |
9 |
Correct |
6 ms |
39248 KB |
Output is correct |
10 |
Correct |
6 ms |
39416 KB |
Output is correct |
11 |
Correct |
7 ms |
39248 KB |
Output is correct |
12 |
Correct |
7 ms |
39248 KB |
Output is correct |
13 |
Correct |
9 ms |
39428 KB |
Output is correct |
14 |
Correct |
7 ms |
39248 KB |
Output is correct |
15 |
Correct |
6 ms |
39248 KB |
Output is correct |
16 |
Correct |
7 ms |
39248 KB |
Output is correct |
17 |
Correct |
7 ms |
39416 KB |
Output is correct |
18 |
Correct |
7 ms |
39452 KB |
Output is correct |
19 |
Correct |
7 ms |
39248 KB |
Output is correct |
20 |
Correct |
8 ms |
39248 KB |
Output is correct |
21 |
Correct |
8 ms |
39760 KB |
Output is correct |
22 |
Correct |
9 ms |
39700 KB |
Output is correct |
23 |
Correct |
7 ms |
39760 KB |
Output is correct |
24 |
Correct |
7 ms |
39760 KB |
Output is correct |
25 |
Correct |
8 ms |
39904 KB |
Output is correct |
26 |
Correct |
8 ms |
39760 KB |
Output is correct |
27 |
Correct |
8 ms |
39504 KB |
Output is correct |
28 |
Correct |
8 ms |
39760 KB |
Output is correct |
29 |
Correct |
9 ms |
40032 KB |
Output is correct |
30 |
Correct |
9 ms |
40016 KB |
Output is correct |
31 |
Correct |
8 ms |
39888 KB |
Output is correct |
32 |
Correct |
10 ms |
39892 KB |
Output is correct |
33 |
Correct |
9 ms |
40016 KB |
Output is correct |
34 |
Correct |
8 ms |
39700 KB |
Output is correct |
35 |
Correct |
8 ms |
39760 KB |
Output is correct |
36 |
Correct |
8 ms |
39504 KB |
Output is correct |
37 |
Correct |
9 ms |
39748 KB |
Output is correct |
38 |
Correct |
7 ms |
39760 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
39380 KB |
Output is correct |
2 |
Correct |
6 ms |
39392 KB |
Output is correct |
3 |
Correct |
7 ms |
39248 KB |
Output is correct |
4 |
Correct |
7 ms |
39248 KB |
Output is correct |
5 |
Correct |
6 ms |
39464 KB |
Output is correct |
6 |
Correct |
7 ms |
39248 KB |
Output is correct |
7 |
Correct |
7 ms |
39248 KB |
Output is correct |
8 |
Correct |
7 ms |
39248 KB |
Output is correct |
9 |
Correct |
6 ms |
39248 KB |
Output is correct |
10 |
Correct |
6 ms |
39416 KB |
Output is correct |
11 |
Correct |
7 ms |
39248 KB |
Output is correct |
12 |
Correct |
7 ms |
39248 KB |
Output is correct |
13 |
Correct |
9 ms |
39428 KB |
Output is correct |
14 |
Correct |
7 ms |
39248 KB |
Output is correct |
15 |
Correct |
6 ms |
39248 KB |
Output is correct |
16 |
Correct |
7 ms |
39248 KB |
Output is correct |
17 |
Correct |
7 ms |
39416 KB |
Output is correct |
18 |
Correct |
7 ms |
39452 KB |
Output is correct |
19 |
Incorrect |
128 ms |
72008 KB |
Output isn't correct |
20 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
39380 KB |
Output is correct |
2 |
Correct |
6 ms |
39392 KB |
Output is correct |
3 |
Correct |
7 ms |
39248 KB |
Output is correct |
4 |
Correct |
7 ms |
39248 KB |
Output is correct |
5 |
Correct |
6 ms |
39464 KB |
Output is correct |
6 |
Correct |
7 ms |
39248 KB |
Output is correct |
7 |
Correct |
7 ms |
39248 KB |
Output is correct |
8 |
Correct |
7 ms |
39248 KB |
Output is correct |
9 |
Correct |
6 ms |
39248 KB |
Output is correct |
10 |
Correct |
6 ms |
39416 KB |
Output is correct |
11 |
Correct |
7 ms |
39248 KB |
Output is correct |
12 |
Correct |
7 ms |
39248 KB |
Output is correct |
13 |
Correct |
9 ms |
39428 KB |
Output is correct |
14 |
Correct |
7 ms |
39248 KB |
Output is correct |
15 |
Correct |
6 ms |
39248 KB |
Output is correct |
16 |
Correct |
7 ms |
39248 KB |
Output is correct |
17 |
Correct |
7 ms |
39416 KB |
Output is correct |
18 |
Correct |
7 ms |
39452 KB |
Output is correct |
19 |
Correct |
7 ms |
39248 KB |
Output is correct |
20 |
Correct |
8 ms |
39248 KB |
Output is correct |
21 |
Correct |
8 ms |
39760 KB |
Output is correct |
22 |
Correct |
9 ms |
39700 KB |
Output is correct |
23 |
Correct |
7 ms |
39760 KB |
Output is correct |
24 |
Correct |
7 ms |
39760 KB |
Output is correct |
25 |
Correct |
8 ms |
39904 KB |
Output is correct |
26 |
Correct |
8 ms |
39760 KB |
Output is correct |
27 |
Correct |
8 ms |
39504 KB |
Output is correct |
28 |
Correct |
8 ms |
39760 KB |
Output is correct |
29 |
Correct |
9 ms |
40032 KB |
Output is correct |
30 |
Correct |
9 ms |
40016 KB |
Output is correct |
31 |
Correct |
8 ms |
39888 KB |
Output is correct |
32 |
Correct |
10 ms |
39892 KB |
Output is correct |
33 |
Correct |
9 ms |
40016 KB |
Output is correct |
34 |
Correct |
8 ms |
39700 KB |
Output is correct |
35 |
Correct |
8 ms |
39760 KB |
Output is correct |
36 |
Correct |
8 ms |
39504 KB |
Output is correct |
37 |
Correct |
9 ms |
39748 KB |
Output is correct |
38 |
Correct |
7 ms |
39760 KB |
Output is correct |
39 |
Incorrect |
128 ms |
72008 KB |
Output isn't correct |
40 |
Halted |
0 ms |
0 KB |
- |