#include <bits/stdc++.h>
#include "race.h"
using namespace std;
typedef long long ll;
const int maxn = 2e5+5;
map<ll,int> se[maxn];
int dep[maxn];
ll val[maxn];
vector<pair<int,int>> adj[maxn];
int ans = 1<<30, gK;
void dfs(int nod, int par){
se[nod][val[nod]] = dep[nod];
for(auto nxt : adj[nod]){
if(nxt.first == par)continue;
dep[nxt.first] = dep[nod]+1;
val[nxt.first] = val[nod]+nxt.second;
dfs(nxt.first,nod);
if(se[nod].size() < se[nxt.first].size())swap(se[nod], se[nxt.first]);
}
for(auto nxt : adj[nod]){
if(nxt.first == par)continue;
for(auto it : se[nxt.first]){
int missing = gK + 2*val[nod] - it.first;
if(se[nod].count(missing)){
ans = min(ans, it.second + se[nod][missing] - 2*dep[nod]);
}
}
for(auto it : se[nxt.first]){
if(se[nod].count(it.first))se[nod][it.first] = min(se[nod][it.first], it.second);
else se[nod][it.first] = it.second;
}
}
}
int best_path(int N, int K, int H[][2], int L[]){
gK = K;
for(int i = 0; i < N-1; ++i){
adj[H[i][0]].push_back({H[i][1],L[i]});
adj[H[i][1]].push_back({H[i][0],L[i]});
}
dfs(0,0);
if(ans == (1<<30))return -1;
return ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
14444 KB |
Output is correct |
2 |
Correct |
11 ms |
14572 KB |
Output is correct |
3 |
Correct |
10 ms |
14444 KB |
Output is correct |
4 |
Correct |
10 ms |
14444 KB |
Output is correct |
5 |
Correct |
11 ms |
14444 KB |
Output is correct |
6 |
Correct |
10 ms |
14444 KB |
Output is correct |
7 |
Correct |
10 ms |
14444 KB |
Output is correct |
8 |
Correct |
10 ms |
14444 KB |
Output is correct |
9 |
Correct |
10 ms |
14444 KB |
Output is correct |
10 |
Correct |
10 ms |
14444 KB |
Output is correct |
11 |
Correct |
12 ms |
14592 KB |
Output is correct |
12 |
Correct |
11 ms |
14444 KB |
Output is correct |
13 |
Correct |
10 ms |
14444 KB |
Output is correct |
14 |
Correct |
11 ms |
14476 KB |
Output is correct |
15 |
Correct |
10 ms |
14444 KB |
Output is correct |
16 |
Correct |
10 ms |
14444 KB |
Output is correct |
17 |
Correct |
10 ms |
14444 KB |
Output is correct |
18 |
Correct |
10 ms |
14572 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
14444 KB |
Output is correct |
2 |
Correct |
11 ms |
14572 KB |
Output is correct |
3 |
Correct |
10 ms |
14444 KB |
Output is correct |
4 |
Correct |
10 ms |
14444 KB |
Output is correct |
5 |
Correct |
11 ms |
14444 KB |
Output is correct |
6 |
Correct |
10 ms |
14444 KB |
Output is correct |
7 |
Correct |
10 ms |
14444 KB |
Output is correct |
8 |
Correct |
10 ms |
14444 KB |
Output is correct |
9 |
Correct |
10 ms |
14444 KB |
Output is correct |
10 |
Correct |
10 ms |
14444 KB |
Output is correct |
11 |
Correct |
12 ms |
14592 KB |
Output is correct |
12 |
Correct |
11 ms |
14444 KB |
Output is correct |
13 |
Correct |
10 ms |
14444 KB |
Output is correct |
14 |
Correct |
11 ms |
14476 KB |
Output is correct |
15 |
Correct |
10 ms |
14444 KB |
Output is correct |
16 |
Correct |
10 ms |
14444 KB |
Output is correct |
17 |
Correct |
10 ms |
14444 KB |
Output is correct |
18 |
Correct |
10 ms |
14572 KB |
Output is correct |
19 |
Correct |
10 ms |
14476 KB |
Output is correct |
20 |
Correct |
10 ms |
14444 KB |
Output is correct |
21 |
Correct |
11 ms |
14700 KB |
Output is correct |
22 |
Correct |
12 ms |
14700 KB |
Output is correct |
23 |
Correct |
12 ms |
14732 KB |
Output is correct |
24 |
Correct |
12 ms |
14848 KB |
Output is correct |
25 |
Correct |
12 ms |
14700 KB |
Output is correct |
26 |
Correct |
12 ms |
14700 KB |
Output is correct |
27 |
Correct |
11 ms |
14572 KB |
Output is correct |
28 |
Correct |
12 ms |
14700 KB |
Output is correct |
29 |
Correct |
12 ms |
14828 KB |
Output is correct |
30 |
Correct |
11 ms |
14700 KB |
Output is correct |
31 |
Correct |
12 ms |
14700 KB |
Output is correct |
32 |
Correct |
12 ms |
14732 KB |
Output is correct |
33 |
Correct |
12 ms |
14828 KB |
Output is correct |
34 |
Correct |
11 ms |
14828 KB |
Output is correct |
35 |
Correct |
11 ms |
14700 KB |
Output is correct |
36 |
Correct |
11 ms |
14700 KB |
Output is correct |
37 |
Correct |
11 ms |
14700 KB |
Output is correct |
38 |
Correct |
13 ms |
14848 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
14444 KB |
Output is correct |
2 |
Correct |
11 ms |
14572 KB |
Output is correct |
3 |
Correct |
10 ms |
14444 KB |
Output is correct |
4 |
Correct |
10 ms |
14444 KB |
Output is correct |
5 |
Correct |
11 ms |
14444 KB |
Output is correct |
6 |
Correct |
10 ms |
14444 KB |
Output is correct |
7 |
Correct |
10 ms |
14444 KB |
Output is correct |
8 |
Correct |
10 ms |
14444 KB |
Output is correct |
9 |
Correct |
10 ms |
14444 KB |
Output is correct |
10 |
Correct |
10 ms |
14444 KB |
Output is correct |
11 |
Correct |
12 ms |
14592 KB |
Output is correct |
12 |
Correct |
11 ms |
14444 KB |
Output is correct |
13 |
Correct |
10 ms |
14444 KB |
Output is correct |
14 |
Correct |
11 ms |
14476 KB |
Output is correct |
15 |
Correct |
10 ms |
14444 KB |
Output is correct |
16 |
Correct |
10 ms |
14444 KB |
Output is correct |
17 |
Correct |
10 ms |
14444 KB |
Output is correct |
18 |
Correct |
10 ms |
14572 KB |
Output is correct |
19 |
Correct |
164 ms |
35304 KB |
Output is correct |
20 |
Correct |
164 ms |
36456 KB |
Output is correct |
21 |
Correct |
154 ms |
36452 KB |
Output is correct |
22 |
Correct |
171 ms |
36196 KB |
Output is correct |
23 |
Correct |
225 ms |
49508 KB |
Output is correct |
24 |
Correct |
160 ms |
40164 KB |
Output is correct |
25 |
Correct |
157 ms |
39136 KB |
Output is correct |
26 |
Correct |
80 ms |
47844 KB |
Output is correct |
27 |
Correct |
252 ms |
48740 KB |
Output is correct |
28 |
Correct |
381 ms |
94052 KB |
Output is correct |
29 |
Correct |
375 ms |
92004 KB |
Output is correct |
30 |
Correct |
264 ms |
48888 KB |
Output is correct |
31 |
Correct |
255 ms |
48740 KB |
Output is correct |
32 |
Correct |
312 ms |
48868 KB |
Output is correct |
33 |
Correct |
313 ms |
53664 KB |
Output is correct |
34 |
Correct |
435 ms |
86628 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
14444 KB |
Output is correct |
2 |
Correct |
11 ms |
14572 KB |
Output is correct |
3 |
Correct |
10 ms |
14444 KB |
Output is correct |
4 |
Correct |
10 ms |
14444 KB |
Output is correct |
5 |
Correct |
11 ms |
14444 KB |
Output is correct |
6 |
Correct |
10 ms |
14444 KB |
Output is correct |
7 |
Correct |
10 ms |
14444 KB |
Output is correct |
8 |
Correct |
10 ms |
14444 KB |
Output is correct |
9 |
Correct |
10 ms |
14444 KB |
Output is correct |
10 |
Correct |
10 ms |
14444 KB |
Output is correct |
11 |
Correct |
12 ms |
14592 KB |
Output is correct |
12 |
Correct |
11 ms |
14444 KB |
Output is correct |
13 |
Correct |
10 ms |
14444 KB |
Output is correct |
14 |
Correct |
11 ms |
14476 KB |
Output is correct |
15 |
Correct |
10 ms |
14444 KB |
Output is correct |
16 |
Correct |
10 ms |
14444 KB |
Output is correct |
17 |
Correct |
10 ms |
14444 KB |
Output is correct |
18 |
Correct |
10 ms |
14572 KB |
Output is correct |
19 |
Correct |
10 ms |
14476 KB |
Output is correct |
20 |
Correct |
10 ms |
14444 KB |
Output is correct |
21 |
Correct |
11 ms |
14700 KB |
Output is correct |
22 |
Correct |
12 ms |
14700 KB |
Output is correct |
23 |
Correct |
12 ms |
14732 KB |
Output is correct |
24 |
Correct |
12 ms |
14848 KB |
Output is correct |
25 |
Correct |
12 ms |
14700 KB |
Output is correct |
26 |
Correct |
12 ms |
14700 KB |
Output is correct |
27 |
Correct |
11 ms |
14572 KB |
Output is correct |
28 |
Correct |
12 ms |
14700 KB |
Output is correct |
29 |
Correct |
12 ms |
14828 KB |
Output is correct |
30 |
Correct |
11 ms |
14700 KB |
Output is correct |
31 |
Correct |
12 ms |
14700 KB |
Output is correct |
32 |
Correct |
12 ms |
14732 KB |
Output is correct |
33 |
Correct |
12 ms |
14828 KB |
Output is correct |
34 |
Correct |
11 ms |
14828 KB |
Output is correct |
35 |
Correct |
11 ms |
14700 KB |
Output is correct |
36 |
Correct |
11 ms |
14700 KB |
Output is correct |
37 |
Correct |
11 ms |
14700 KB |
Output is correct |
38 |
Correct |
13 ms |
14848 KB |
Output is correct |
39 |
Correct |
164 ms |
35304 KB |
Output is correct |
40 |
Correct |
164 ms |
36456 KB |
Output is correct |
41 |
Correct |
154 ms |
36452 KB |
Output is correct |
42 |
Correct |
171 ms |
36196 KB |
Output is correct |
43 |
Correct |
225 ms |
49508 KB |
Output is correct |
44 |
Correct |
160 ms |
40164 KB |
Output is correct |
45 |
Correct |
157 ms |
39136 KB |
Output is correct |
46 |
Correct |
80 ms |
47844 KB |
Output is correct |
47 |
Correct |
252 ms |
48740 KB |
Output is correct |
48 |
Correct |
381 ms |
94052 KB |
Output is correct |
49 |
Correct |
375 ms |
92004 KB |
Output is correct |
50 |
Correct |
264 ms |
48888 KB |
Output is correct |
51 |
Correct |
255 ms |
48740 KB |
Output is correct |
52 |
Correct |
312 ms |
48868 KB |
Output is correct |
53 |
Correct |
313 ms |
53664 KB |
Output is correct |
54 |
Correct |
435 ms |
86628 KB |
Output is correct |
55 |
Correct |
27 ms |
17784 KB |
Output is correct |
56 |
Correct |
19 ms |
16364 KB |
Output is correct |
57 |
Correct |
96 ms |
34276 KB |
Output is correct |
58 |
Correct |
70 ms |
27992 KB |
Output is correct |
59 |
Correct |
116 ms |
54244 KB |
Output is correct |
60 |
Correct |
367 ms |
92636 KB |
Output is correct |
61 |
Correct |
292 ms |
52196 KB |
Output is correct |
62 |
Correct |
248 ms |
48740 KB |
Output is correct |
63 |
Correct |
323 ms |
48868 KB |
Output is correct |
64 |
Correct |
563 ms |
100452 KB |
Output is correct |
65 |
Correct |
549 ms |
100068 KB |
Output is correct |
66 |
Correct |
393 ms |
87512 KB |
Output is correct |
67 |
Correct |
231 ms |
43344 KB |
Output is correct |
68 |
Correct |
421 ms |
65508 KB |
Output is correct |
69 |
Correct |
422 ms |
66020 KB |
Output is correct |
70 |
Correct |
419 ms |
63204 KB |
Output is correct |