#include "bits/stdc++.h"
using namespace std;
#define ff first
#define ss second
#define all(v) v.begin(), v.end()
#define ll long long
#define pb push_back
#define pii pair<int, int>
#define pli pair<ll, int>
#define pll pair<ll, ll>
#define tr(i, c) for(auto i = c.begin(); i != c.end(); ++i)
#define wr puts("----------------")
template<class T>bool umin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T>bool umax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
const int INF = 1e9;
const int N = 2e5+5;
int ret, n, k;
vector<pii> adj[N];
map<int, int> mp[N];
void dfs(int x, int pr, int d, int lvl){
mp[x][d] = lvl;
tr(it, adj[x])
if(it->ff!=pr){
dfs(it->ff, x, d+it->ss, lvl+1);
if((int)mp[it->ff].size()>(int)mp[x].size())
swap(mp[x], mp[it->ff]);
for(auto &i : mp[it->ff])
if(mp[x].find(k+2*d-i.ff)!=mp[x].end())
umin(ret, mp[x][k+2*d-i.ff]+i.ss-2*lvl);
for(auto &i : mp[it->ff]){
if(mp[x].find(i.ff)==mp[x].end())
mp[x][i.ff]=i.ss;
umin(mp[x][i.ff], i.ss);
}
}
}
int best_path(int N, int K, int H[][2], int L[]){
n = N, k = K;
for(int i = 0; i < n-1; ++i)
adj[H[i][0]].pb({H[i][1], L[i]}), adj[H[i][1]].pb({H[i][0], L[i]});
ret = INF;
dfs(0, -1, 0, 0);
return (ret==INF?-1:ret);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
18000 KB |
Output is correct |
2 |
Correct |
4 ms |
18000 KB |
Output is correct |
3 |
Correct |
4 ms |
18000 KB |
Output is correct |
4 |
Correct |
4 ms |
18000 KB |
Output is correct |
5 |
Correct |
5 ms |
18208 KB |
Output is correct |
6 |
Correct |
5 ms |
18000 KB |
Output is correct |
7 |
Correct |
4 ms |
18000 KB |
Output is correct |
8 |
Correct |
4 ms |
18000 KB |
Output is correct |
9 |
Correct |
5 ms |
18176 KB |
Output is correct |
10 |
Correct |
4 ms |
18000 KB |
Output is correct |
11 |
Correct |
5 ms |
18168 KB |
Output is correct |
12 |
Correct |
4 ms |
18000 KB |
Output is correct |
13 |
Correct |
4 ms |
18176 KB |
Output is correct |
14 |
Correct |
4 ms |
18000 KB |
Output is correct |
15 |
Correct |
5 ms |
18000 KB |
Output is correct |
16 |
Correct |
4 ms |
18000 KB |
Output is correct |
17 |
Correct |
4 ms |
18000 KB |
Output is correct |
18 |
Correct |
4 ms |
18000 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
18000 KB |
Output is correct |
2 |
Correct |
4 ms |
18000 KB |
Output is correct |
3 |
Correct |
4 ms |
18000 KB |
Output is correct |
4 |
Correct |
4 ms |
18000 KB |
Output is correct |
5 |
Correct |
5 ms |
18208 KB |
Output is correct |
6 |
Correct |
5 ms |
18000 KB |
Output is correct |
7 |
Correct |
4 ms |
18000 KB |
Output is correct |
8 |
Correct |
4 ms |
18000 KB |
Output is correct |
9 |
Correct |
5 ms |
18176 KB |
Output is correct |
10 |
Correct |
4 ms |
18000 KB |
Output is correct |
11 |
Correct |
5 ms |
18168 KB |
Output is correct |
12 |
Correct |
4 ms |
18000 KB |
Output is correct |
13 |
Correct |
4 ms |
18176 KB |
Output is correct |
14 |
Correct |
4 ms |
18000 KB |
Output is correct |
15 |
Correct |
5 ms |
18000 KB |
Output is correct |
16 |
Correct |
4 ms |
18000 KB |
Output is correct |
17 |
Correct |
4 ms |
18000 KB |
Output is correct |
18 |
Correct |
4 ms |
18000 KB |
Output is correct |
19 |
Correct |
4 ms |
18176 KB |
Output is correct |
20 |
Correct |
5 ms |
18000 KB |
Output is correct |
21 |
Correct |
5 ms |
18256 KB |
Output is correct |
22 |
Correct |
5 ms |
18184 KB |
Output is correct |
23 |
Correct |
6 ms |
18256 KB |
Output is correct |
24 |
Correct |
5 ms |
18256 KB |
Output is correct |
25 |
Correct |
5 ms |
18256 KB |
Output is correct |
26 |
Correct |
5 ms |
18256 KB |
Output is correct |
27 |
Correct |
5 ms |
18256 KB |
Output is correct |
28 |
Correct |
5 ms |
18256 KB |
Output is correct |
29 |
Correct |
6 ms |
18256 KB |
Output is correct |
30 |
Correct |
6 ms |
18404 KB |
Output is correct |
31 |
Correct |
5 ms |
18256 KB |
Output is correct |
32 |
Correct |
5 ms |
18256 KB |
Output is correct |
33 |
Correct |
6 ms |
18256 KB |
Output is correct |
34 |
Correct |
4 ms |
18256 KB |
Output is correct |
35 |
Correct |
6 ms |
18256 KB |
Output is correct |
36 |
Correct |
5 ms |
18180 KB |
Output is correct |
37 |
Correct |
4 ms |
18428 KB |
Output is correct |
38 |
Correct |
5 ms |
18256 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
18000 KB |
Output is correct |
2 |
Correct |
4 ms |
18000 KB |
Output is correct |
3 |
Correct |
4 ms |
18000 KB |
Output is correct |
4 |
Correct |
4 ms |
18000 KB |
Output is correct |
5 |
Correct |
5 ms |
18208 KB |
Output is correct |
6 |
Correct |
5 ms |
18000 KB |
Output is correct |
7 |
Correct |
4 ms |
18000 KB |
Output is correct |
8 |
Correct |
4 ms |
18000 KB |
Output is correct |
9 |
Correct |
5 ms |
18176 KB |
Output is correct |
10 |
Correct |
4 ms |
18000 KB |
Output is correct |
11 |
Correct |
5 ms |
18168 KB |
Output is correct |
12 |
Correct |
4 ms |
18000 KB |
Output is correct |
13 |
Correct |
4 ms |
18176 KB |
Output is correct |
14 |
Correct |
4 ms |
18000 KB |
Output is correct |
15 |
Correct |
5 ms |
18000 KB |
Output is correct |
16 |
Correct |
4 ms |
18000 KB |
Output is correct |
17 |
Correct |
4 ms |
18000 KB |
Output is correct |
18 |
Correct |
4 ms |
18000 KB |
Output is correct |
19 |
Correct |
90 ms |
36880 KB |
Output is correct |
20 |
Correct |
92 ms |
37064 KB |
Output is correct |
21 |
Correct |
93 ms |
36680 KB |
Output is correct |
22 |
Correct |
123 ms |
36476 KB |
Output is correct |
23 |
Correct |
163 ms |
46108 KB |
Output is correct |
24 |
Correct |
101 ms |
39240 KB |
Output is correct |
25 |
Correct |
83 ms |
37448 KB |
Output is correct |
26 |
Correct |
49 ms |
43604 KB |
Output is correct |
27 |
Correct |
140 ms |
45128 KB |
Output is correct |
28 |
Correct |
245 ms |
76564 KB |
Output is correct |
29 |
Correct |
236 ms |
75080 KB |
Output is correct |
30 |
Correct |
141 ms |
45060 KB |
Output is correct |
31 |
Correct |
139 ms |
45128 KB |
Output is correct |
32 |
Correct |
159 ms |
45132 KB |
Output is correct |
33 |
Correct |
164 ms |
48380 KB |
Output is correct |
34 |
Correct |
301 ms |
73288 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
18000 KB |
Output is correct |
2 |
Correct |
4 ms |
18000 KB |
Output is correct |
3 |
Correct |
4 ms |
18000 KB |
Output is correct |
4 |
Correct |
4 ms |
18000 KB |
Output is correct |
5 |
Correct |
5 ms |
18208 KB |
Output is correct |
6 |
Correct |
5 ms |
18000 KB |
Output is correct |
7 |
Correct |
4 ms |
18000 KB |
Output is correct |
8 |
Correct |
4 ms |
18000 KB |
Output is correct |
9 |
Correct |
5 ms |
18176 KB |
Output is correct |
10 |
Correct |
4 ms |
18000 KB |
Output is correct |
11 |
Correct |
5 ms |
18168 KB |
Output is correct |
12 |
Correct |
4 ms |
18000 KB |
Output is correct |
13 |
Correct |
4 ms |
18176 KB |
Output is correct |
14 |
Correct |
4 ms |
18000 KB |
Output is correct |
15 |
Correct |
5 ms |
18000 KB |
Output is correct |
16 |
Correct |
4 ms |
18000 KB |
Output is correct |
17 |
Correct |
4 ms |
18000 KB |
Output is correct |
18 |
Correct |
4 ms |
18000 KB |
Output is correct |
19 |
Correct |
4 ms |
18176 KB |
Output is correct |
20 |
Correct |
5 ms |
18000 KB |
Output is correct |
21 |
Correct |
5 ms |
18256 KB |
Output is correct |
22 |
Correct |
5 ms |
18184 KB |
Output is correct |
23 |
Correct |
6 ms |
18256 KB |
Output is correct |
24 |
Correct |
5 ms |
18256 KB |
Output is correct |
25 |
Correct |
5 ms |
18256 KB |
Output is correct |
26 |
Correct |
5 ms |
18256 KB |
Output is correct |
27 |
Correct |
5 ms |
18256 KB |
Output is correct |
28 |
Correct |
5 ms |
18256 KB |
Output is correct |
29 |
Correct |
6 ms |
18256 KB |
Output is correct |
30 |
Correct |
6 ms |
18404 KB |
Output is correct |
31 |
Correct |
5 ms |
18256 KB |
Output is correct |
32 |
Correct |
5 ms |
18256 KB |
Output is correct |
33 |
Correct |
6 ms |
18256 KB |
Output is correct |
34 |
Correct |
4 ms |
18256 KB |
Output is correct |
35 |
Correct |
6 ms |
18256 KB |
Output is correct |
36 |
Correct |
5 ms |
18180 KB |
Output is correct |
37 |
Correct |
4 ms |
18428 KB |
Output is correct |
38 |
Correct |
5 ms |
18256 KB |
Output is correct |
39 |
Correct |
90 ms |
36880 KB |
Output is correct |
40 |
Correct |
92 ms |
37064 KB |
Output is correct |
41 |
Correct |
93 ms |
36680 KB |
Output is correct |
42 |
Correct |
123 ms |
36476 KB |
Output is correct |
43 |
Correct |
163 ms |
46108 KB |
Output is correct |
44 |
Correct |
101 ms |
39240 KB |
Output is correct |
45 |
Correct |
83 ms |
37448 KB |
Output is correct |
46 |
Correct |
49 ms |
43604 KB |
Output is correct |
47 |
Correct |
140 ms |
45128 KB |
Output is correct |
48 |
Correct |
245 ms |
76564 KB |
Output is correct |
49 |
Correct |
236 ms |
75080 KB |
Output is correct |
50 |
Correct |
141 ms |
45060 KB |
Output is correct |
51 |
Correct |
139 ms |
45128 KB |
Output is correct |
52 |
Correct |
159 ms |
45132 KB |
Output is correct |
53 |
Correct |
164 ms |
48380 KB |
Output is correct |
54 |
Correct |
301 ms |
73288 KB |
Output is correct |
55 |
Correct |
17 ms |
20560 KB |
Output is correct |
56 |
Correct |
13 ms |
19536 KB |
Output is correct |
57 |
Correct |
53 ms |
35096 KB |
Output is correct |
58 |
Correct |
40 ms |
29952 KB |
Output is correct |
59 |
Correct |
82 ms |
48196 KB |
Output is correct |
60 |
Correct |
219 ms |
75336 KB |
Output is correct |
61 |
Correct |
186 ms |
47764 KB |
Output is correct |
62 |
Correct |
146 ms |
45128 KB |
Output is correct |
63 |
Correct |
166 ms |
45128 KB |
Output is correct |
64 |
Correct |
379 ms |
86584 KB |
Output is correct |
65 |
Correct |
375 ms |
85320 KB |
Output is correct |
66 |
Correct |
233 ms |
72264 KB |
Output is correct |
67 |
Correct |
104 ms |
41656 KB |
Output is correct |
68 |
Correct |
284 ms |
58184 KB |
Output is correct |
69 |
Correct |
309 ms |
62024 KB |
Output is correct |
70 |
Correct |
254 ms |
56876 KB |
Output is correct |