#include <bits/stdc++.h>
#include "race.h"
using namespace std;
#define db long double
#define ll long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vl vector<ll>
#define vii vector<pii>
#define vll vector<pll>
#define endl '\n'
#define all(x) x.begin(), x.end()
#define fastio\
ios_base::sync_with_stdio(0);\
cin.tie(0);\
cout.tie(0)\
const int sz = 2e5 + 5;
vll g[sz];
ll n, k, h[sz], res = 1e9;
vl v[sz];
set<pll> dfs(ll node, ll par, ll w){
h[node] = h[par] + 1;
set<pll> st;
for(pll i : g[node]){
if(i.first == par) continue;
set<pll> temp = dfs(i.first, node, i.second);
if(temp.size() > st.size()) swap(st, temp);
for(pll j : temp){
auto it = st.lower_bound({k - j.first, 0});
if(it != st.end() and j.first + (*it).first == k) res = min(res, j.second + (*it).second - 2 * h[node]);
}
for(pll j : temp){
st.insert(j);
}
}
set<pll> fnl;
for(pll i : st){
if(i.first == k) res = min(res, i.second - h[node]);
fnl.insert({i.first + w, i.second});
}
fnl.insert({w, h[node]});
return fnl;
}
int best_path(int N, int K, int H[][2], int L[]){
n = N, k = K;
for(int i = 0; i < n; i++){
g[H[i][0]].push_back({H[i][1], L[i]});
g[H[i][1]].push_back({H[i][0], L[i]});
}
h[0] = -1;
dfs(0, 0, 0);
res = (res == 1e9 ? -1 : res);
return res;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
14936 KB |
Output is correct |
2 |
Correct |
3 ms |
14936 KB |
Output is correct |
3 |
Correct |
3 ms |
14936 KB |
Output is correct |
4 |
Correct |
3 ms |
15044 KB |
Output is correct |
5 |
Correct |
3 ms |
14940 KB |
Output is correct |
6 |
Correct |
3 ms |
14940 KB |
Output is correct |
7 |
Correct |
3 ms |
14940 KB |
Output is correct |
8 |
Correct |
4 ms |
15196 KB |
Output is correct |
9 |
Correct |
3 ms |
14940 KB |
Output is correct |
10 |
Correct |
3 ms |
14940 KB |
Output is correct |
11 |
Correct |
3 ms |
14940 KB |
Output is correct |
12 |
Correct |
3 ms |
14940 KB |
Output is correct |
13 |
Correct |
3 ms |
14936 KB |
Output is correct |
14 |
Correct |
3 ms |
14940 KB |
Output is correct |
15 |
Correct |
3 ms |
14940 KB |
Output is correct |
16 |
Correct |
3 ms |
14940 KB |
Output is correct |
17 |
Correct |
3 ms |
14940 KB |
Output is correct |
18 |
Correct |
3 ms |
14940 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
14936 KB |
Output is correct |
2 |
Correct |
3 ms |
14936 KB |
Output is correct |
3 |
Correct |
3 ms |
14936 KB |
Output is correct |
4 |
Correct |
3 ms |
15044 KB |
Output is correct |
5 |
Correct |
3 ms |
14940 KB |
Output is correct |
6 |
Correct |
3 ms |
14940 KB |
Output is correct |
7 |
Correct |
3 ms |
14940 KB |
Output is correct |
8 |
Correct |
4 ms |
15196 KB |
Output is correct |
9 |
Correct |
3 ms |
14940 KB |
Output is correct |
10 |
Correct |
3 ms |
14940 KB |
Output is correct |
11 |
Correct |
3 ms |
14940 KB |
Output is correct |
12 |
Correct |
3 ms |
14940 KB |
Output is correct |
13 |
Correct |
3 ms |
14936 KB |
Output is correct |
14 |
Correct |
3 ms |
14940 KB |
Output is correct |
15 |
Correct |
3 ms |
14940 KB |
Output is correct |
16 |
Correct |
3 ms |
14940 KB |
Output is correct |
17 |
Correct |
3 ms |
14940 KB |
Output is correct |
18 |
Correct |
3 ms |
14940 KB |
Output is correct |
19 |
Correct |
3 ms |
14936 KB |
Output is correct |
20 |
Correct |
3 ms |
14940 KB |
Output is correct |
21 |
Correct |
4 ms |
15196 KB |
Output is correct |
22 |
Correct |
4 ms |
15032 KB |
Output is correct |
23 |
Correct |
5 ms |
15196 KB |
Output is correct |
24 |
Correct |
4 ms |
15196 KB |
Output is correct |
25 |
Correct |
4 ms |
15196 KB |
Output is correct |
26 |
Correct |
4 ms |
15196 KB |
Output is correct |
27 |
Correct |
3 ms |
15036 KB |
Output is correct |
28 |
Correct |
4 ms |
15028 KB |
Output is correct |
29 |
Correct |
4 ms |
15196 KB |
Output is correct |
30 |
Correct |
4 ms |
15196 KB |
Output is correct |
31 |
Correct |
4 ms |
15196 KB |
Output is correct |
32 |
Correct |
4 ms |
15196 KB |
Output is correct |
33 |
Correct |
4 ms |
15196 KB |
Output is correct |
34 |
Correct |
10 ms |
15196 KB |
Output is correct |
35 |
Correct |
11 ms |
15200 KB |
Output is correct |
36 |
Correct |
13 ms |
15284 KB |
Output is correct |
37 |
Correct |
8 ms |
15200 KB |
Output is correct |
38 |
Correct |
6 ms |
15200 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
14936 KB |
Output is correct |
2 |
Correct |
3 ms |
14936 KB |
Output is correct |
3 |
Correct |
3 ms |
14936 KB |
Output is correct |
4 |
Correct |
3 ms |
15044 KB |
Output is correct |
5 |
Correct |
3 ms |
14940 KB |
Output is correct |
6 |
Correct |
3 ms |
14940 KB |
Output is correct |
7 |
Correct |
3 ms |
14940 KB |
Output is correct |
8 |
Correct |
4 ms |
15196 KB |
Output is correct |
9 |
Correct |
3 ms |
14940 KB |
Output is correct |
10 |
Correct |
3 ms |
14940 KB |
Output is correct |
11 |
Correct |
3 ms |
14940 KB |
Output is correct |
12 |
Correct |
3 ms |
14940 KB |
Output is correct |
13 |
Correct |
3 ms |
14936 KB |
Output is correct |
14 |
Correct |
3 ms |
14940 KB |
Output is correct |
15 |
Correct |
3 ms |
14940 KB |
Output is correct |
16 |
Correct |
3 ms |
14940 KB |
Output is correct |
17 |
Correct |
3 ms |
14940 KB |
Output is correct |
18 |
Correct |
3 ms |
14940 KB |
Output is correct |
19 |
Correct |
152 ms |
23984 KB |
Output is correct |
20 |
Correct |
147 ms |
24028 KB |
Output is correct |
21 |
Correct |
121 ms |
23896 KB |
Output is correct |
22 |
Correct |
102 ms |
23892 KB |
Output is correct |
23 |
Correct |
152 ms |
24988 KB |
Output is correct |
24 |
Correct |
83 ms |
23552 KB |
Output is correct |
25 |
Execution timed out |
3104 ms |
38056 KB |
Time limit exceeded |
26 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
14936 KB |
Output is correct |
2 |
Correct |
3 ms |
14936 KB |
Output is correct |
3 |
Correct |
3 ms |
14936 KB |
Output is correct |
4 |
Correct |
3 ms |
15044 KB |
Output is correct |
5 |
Correct |
3 ms |
14940 KB |
Output is correct |
6 |
Correct |
3 ms |
14940 KB |
Output is correct |
7 |
Correct |
3 ms |
14940 KB |
Output is correct |
8 |
Correct |
4 ms |
15196 KB |
Output is correct |
9 |
Correct |
3 ms |
14940 KB |
Output is correct |
10 |
Correct |
3 ms |
14940 KB |
Output is correct |
11 |
Correct |
3 ms |
14940 KB |
Output is correct |
12 |
Correct |
3 ms |
14940 KB |
Output is correct |
13 |
Correct |
3 ms |
14936 KB |
Output is correct |
14 |
Correct |
3 ms |
14940 KB |
Output is correct |
15 |
Correct |
3 ms |
14940 KB |
Output is correct |
16 |
Correct |
3 ms |
14940 KB |
Output is correct |
17 |
Correct |
3 ms |
14940 KB |
Output is correct |
18 |
Correct |
3 ms |
14940 KB |
Output is correct |
19 |
Correct |
3 ms |
14936 KB |
Output is correct |
20 |
Correct |
3 ms |
14940 KB |
Output is correct |
21 |
Correct |
4 ms |
15196 KB |
Output is correct |
22 |
Correct |
4 ms |
15032 KB |
Output is correct |
23 |
Correct |
5 ms |
15196 KB |
Output is correct |
24 |
Correct |
4 ms |
15196 KB |
Output is correct |
25 |
Correct |
4 ms |
15196 KB |
Output is correct |
26 |
Correct |
4 ms |
15196 KB |
Output is correct |
27 |
Correct |
3 ms |
15036 KB |
Output is correct |
28 |
Correct |
4 ms |
15028 KB |
Output is correct |
29 |
Correct |
4 ms |
15196 KB |
Output is correct |
30 |
Correct |
4 ms |
15196 KB |
Output is correct |
31 |
Correct |
4 ms |
15196 KB |
Output is correct |
32 |
Correct |
4 ms |
15196 KB |
Output is correct |
33 |
Correct |
4 ms |
15196 KB |
Output is correct |
34 |
Correct |
10 ms |
15196 KB |
Output is correct |
35 |
Correct |
11 ms |
15200 KB |
Output is correct |
36 |
Correct |
13 ms |
15284 KB |
Output is correct |
37 |
Correct |
8 ms |
15200 KB |
Output is correct |
38 |
Correct |
6 ms |
15200 KB |
Output is correct |
39 |
Correct |
152 ms |
23984 KB |
Output is correct |
40 |
Correct |
147 ms |
24028 KB |
Output is correct |
41 |
Correct |
121 ms |
23896 KB |
Output is correct |
42 |
Correct |
102 ms |
23892 KB |
Output is correct |
43 |
Correct |
152 ms |
24988 KB |
Output is correct |
44 |
Correct |
83 ms |
23552 KB |
Output is correct |
45 |
Execution timed out |
3104 ms |
38056 KB |
Time limit exceeded |
46 |
Halted |
0 ms |
0 KB |
- |