#include<race.h>
#include<vector>
#include<set>
#include<iostream>
using namespace std;
int nrPaths;
set<pair<long long,int> > S[200005];
vector<pair<int,int> > A[200005];
int HPath[200005],Lev[200005];
long long Dist[200005];
int dfs(int nod, int p, int L)
{
int rez=1000000000;
for(auto other:A[nod])
{
if(other.first==p)
continue;
Dist[other.first]=Dist[nod]+other.second;
Lev[other.first]=Lev[nod]+1;
rez=min(rez,dfs(other.first,nod,L));
if(S[HPath[other.first]].size()>S[HPath[nod]].size())
HPath[nod]=HPath[other.first];
}
if(HPath[nod]==0)
HPath[nod]=++nrPaths;
int path=HPath[nod];
for(auto other:A[nod])
{
if(other.first==p || path==HPath[other.first])
continue;
for(auto el:S[HPath[other.first]]) //mi le lua si pe alea care erau pe acelasi path
{
long long dist=L-(el.first-Dist[nod])+Dist[nod];
if(dist>Dist[nod])
{
set<pair<long long,int> >::iterator it=S[path].lower_bound({dist,0});
if(it!=S[path].end() && (*it).first==dist)
rez=min(rez,(*it).second+el.second-2*Lev[nod]);
}
}
for(auto el:S[HPath[other.first]])
{
set<pair<long long,int> >::iterator it=S[path].lower_bound({el.first,0});
if(it!=S[path].end() && (*it).first==el.first)
{
if(el.second<(*it).second)
{
S[path].erase(it);
S[path].insert(el);
}
}
else
S[path].insert(el);
}
}
S[path].insert({Dist[nod],Lev[nod]});
set<pair<long long,int> >::iterator it=S[path].lower_bound({Dist[nod]+L,0});
if(it!=S[path].end() && (*it).first==Dist[nod]+L)
rez=min(rez,(*it).second-Lev[nod]);
return rez;
}
int best_path(int n, int k, int E[][2], int L[])
{
for(int i=0; i<=n-2; i++)
{
A[E[i][0]].push_back({E[i][1],L[i]});
A[E[i][1]].push_back({E[i][0],L[i]});
}
int rez=dfs(0,-1,k);
if(rez==1000000000)
rez=-1;
return rez;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
14464 KB |
Output is correct |
2 |
Correct |
13 ms |
14464 KB |
Output is correct |
3 |
Correct |
13 ms |
14464 KB |
Output is correct |
4 |
Correct |
13 ms |
14464 KB |
Output is correct |
5 |
Correct |
12 ms |
14592 KB |
Output is correct |
6 |
Correct |
13 ms |
14464 KB |
Output is correct |
7 |
Correct |
13 ms |
14464 KB |
Output is correct |
8 |
Correct |
13 ms |
14464 KB |
Output is correct |
9 |
Correct |
13 ms |
14464 KB |
Output is correct |
10 |
Correct |
13 ms |
14464 KB |
Output is correct |
11 |
Correct |
13 ms |
14464 KB |
Output is correct |
12 |
Correct |
13 ms |
14464 KB |
Output is correct |
13 |
Correct |
13 ms |
14464 KB |
Output is correct |
14 |
Correct |
13 ms |
14464 KB |
Output is correct |
15 |
Correct |
13 ms |
14460 KB |
Output is correct |
16 |
Correct |
14 ms |
14464 KB |
Output is correct |
17 |
Correct |
12 ms |
14464 KB |
Output is correct |
18 |
Correct |
13 ms |
14464 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
14464 KB |
Output is correct |
2 |
Correct |
13 ms |
14464 KB |
Output is correct |
3 |
Correct |
13 ms |
14464 KB |
Output is correct |
4 |
Correct |
13 ms |
14464 KB |
Output is correct |
5 |
Correct |
12 ms |
14592 KB |
Output is correct |
6 |
Correct |
13 ms |
14464 KB |
Output is correct |
7 |
Correct |
13 ms |
14464 KB |
Output is correct |
8 |
Correct |
13 ms |
14464 KB |
Output is correct |
9 |
Correct |
13 ms |
14464 KB |
Output is correct |
10 |
Correct |
13 ms |
14464 KB |
Output is correct |
11 |
Correct |
13 ms |
14464 KB |
Output is correct |
12 |
Correct |
13 ms |
14464 KB |
Output is correct |
13 |
Correct |
13 ms |
14464 KB |
Output is correct |
14 |
Correct |
13 ms |
14464 KB |
Output is correct |
15 |
Correct |
13 ms |
14460 KB |
Output is correct |
16 |
Correct |
14 ms |
14464 KB |
Output is correct |
17 |
Correct |
12 ms |
14464 KB |
Output is correct |
18 |
Correct |
13 ms |
14464 KB |
Output is correct |
19 |
Correct |
13 ms |
14464 KB |
Output is correct |
20 |
Correct |
13 ms |
14464 KB |
Output is correct |
21 |
Correct |
14 ms |
14720 KB |
Output is correct |
22 |
Correct |
14 ms |
14720 KB |
Output is correct |
23 |
Correct |
17 ms |
14720 KB |
Output is correct |
24 |
Correct |
14 ms |
14720 KB |
Output is correct |
25 |
Correct |
15 ms |
14720 KB |
Output is correct |
26 |
Correct |
14 ms |
14720 KB |
Output is correct |
27 |
Correct |
13 ms |
14592 KB |
Output is correct |
28 |
Correct |
15 ms |
14720 KB |
Output is correct |
29 |
Correct |
14 ms |
14720 KB |
Output is correct |
30 |
Correct |
14 ms |
14720 KB |
Output is correct |
31 |
Correct |
14 ms |
14720 KB |
Output is correct |
32 |
Correct |
14 ms |
14720 KB |
Output is correct |
33 |
Correct |
14 ms |
14720 KB |
Output is correct |
34 |
Correct |
14 ms |
14720 KB |
Output is correct |
35 |
Correct |
14 ms |
14592 KB |
Output is correct |
36 |
Correct |
14 ms |
14592 KB |
Output is correct |
37 |
Correct |
13 ms |
14592 KB |
Output is correct |
38 |
Correct |
13 ms |
14592 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
14464 KB |
Output is correct |
2 |
Correct |
13 ms |
14464 KB |
Output is correct |
3 |
Correct |
13 ms |
14464 KB |
Output is correct |
4 |
Correct |
13 ms |
14464 KB |
Output is correct |
5 |
Correct |
12 ms |
14592 KB |
Output is correct |
6 |
Correct |
13 ms |
14464 KB |
Output is correct |
7 |
Correct |
13 ms |
14464 KB |
Output is correct |
8 |
Correct |
13 ms |
14464 KB |
Output is correct |
9 |
Correct |
13 ms |
14464 KB |
Output is correct |
10 |
Correct |
13 ms |
14464 KB |
Output is correct |
11 |
Correct |
13 ms |
14464 KB |
Output is correct |
12 |
Correct |
13 ms |
14464 KB |
Output is correct |
13 |
Correct |
13 ms |
14464 KB |
Output is correct |
14 |
Correct |
13 ms |
14464 KB |
Output is correct |
15 |
Correct |
13 ms |
14460 KB |
Output is correct |
16 |
Correct |
14 ms |
14464 KB |
Output is correct |
17 |
Correct |
12 ms |
14464 KB |
Output is correct |
18 |
Correct |
13 ms |
14464 KB |
Output is correct |
19 |
Correct |
130 ms |
33272 KB |
Output is correct |
20 |
Correct |
135 ms |
33272 KB |
Output is correct |
21 |
Correct |
127 ms |
33272 KB |
Output is correct |
22 |
Correct |
126 ms |
33400 KB |
Output is correct |
23 |
Correct |
168 ms |
46584 KB |
Output is correct |
24 |
Correct |
133 ms |
39672 KB |
Output is correct |
25 |
Correct |
119 ms |
36984 KB |
Output is correct |
26 |
Correct |
98 ms |
45176 KB |
Output is correct |
27 |
Correct |
210 ms |
42104 KB |
Output is correct |
28 |
Correct |
280 ms |
74912 KB |
Output is correct |
29 |
Correct |
263 ms |
73208 KB |
Output is correct |
30 |
Correct |
214 ms |
42104 KB |
Output is correct |
31 |
Correct |
214 ms |
42232 KB |
Output is correct |
32 |
Correct |
243 ms |
42204 KB |
Output is correct |
33 |
Correct |
206 ms |
40952 KB |
Output is correct |
34 |
Correct |
340 ms |
72828 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
14464 KB |
Output is correct |
2 |
Correct |
13 ms |
14464 KB |
Output is correct |
3 |
Correct |
13 ms |
14464 KB |
Output is correct |
4 |
Correct |
13 ms |
14464 KB |
Output is correct |
5 |
Correct |
12 ms |
14592 KB |
Output is correct |
6 |
Correct |
13 ms |
14464 KB |
Output is correct |
7 |
Correct |
13 ms |
14464 KB |
Output is correct |
8 |
Correct |
13 ms |
14464 KB |
Output is correct |
9 |
Correct |
13 ms |
14464 KB |
Output is correct |
10 |
Correct |
13 ms |
14464 KB |
Output is correct |
11 |
Correct |
13 ms |
14464 KB |
Output is correct |
12 |
Correct |
13 ms |
14464 KB |
Output is correct |
13 |
Correct |
13 ms |
14464 KB |
Output is correct |
14 |
Correct |
13 ms |
14464 KB |
Output is correct |
15 |
Correct |
13 ms |
14460 KB |
Output is correct |
16 |
Correct |
14 ms |
14464 KB |
Output is correct |
17 |
Correct |
12 ms |
14464 KB |
Output is correct |
18 |
Correct |
13 ms |
14464 KB |
Output is correct |
19 |
Correct |
13 ms |
14464 KB |
Output is correct |
20 |
Correct |
13 ms |
14464 KB |
Output is correct |
21 |
Correct |
14 ms |
14720 KB |
Output is correct |
22 |
Correct |
14 ms |
14720 KB |
Output is correct |
23 |
Correct |
17 ms |
14720 KB |
Output is correct |
24 |
Correct |
14 ms |
14720 KB |
Output is correct |
25 |
Correct |
15 ms |
14720 KB |
Output is correct |
26 |
Correct |
14 ms |
14720 KB |
Output is correct |
27 |
Correct |
13 ms |
14592 KB |
Output is correct |
28 |
Correct |
15 ms |
14720 KB |
Output is correct |
29 |
Correct |
14 ms |
14720 KB |
Output is correct |
30 |
Correct |
14 ms |
14720 KB |
Output is correct |
31 |
Correct |
14 ms |
14720 KB |
Output is correct |
32 |
Correct |
14 ms |
14720 KB |
Output is correct |
33 |
Correct |
14 ms |
14720 KB |
Output is correct |
34 |
Correct |
14 ms |
14720 KB |
Output is correct |
35 |
Correct |
14 ms |
14592 KB |
Output is correct |
36 |
Correct |
14 ms |
14592 KB |
Output is correct |
37 |
Correct |
13 ms |
14592 KB |
Output is correct |
38 |
Correct |
13 ms |
14592 KB |
Output is correct |
39 |
Correct |
130 ms |
33272 KB |
Output is correct |
40 |
Correct |
135 ms |
33272 KB |
Output is correct |
41 |
Correct |
127 ms |
33272 KB |
Output is correct |
42 |
Correct |
126 ms |
33400 KB |
Output is correct |
43 |
Correct |
168 ms |
46584 KB |
Output is correct |
44 |
Correct |
133 ms |
39672 KB |
Output is correct |
45 |
Correct |
119 ms |
36984 KB |
Output is correct |
46 |
Correct |
98 ms |
45176 KB |
Output is correct |
47 |
Correct |
210 ms |
42104 KB |
Output is correct |
48 |
Correct |
280 ms |
74912 KB |
Output is correct |
49 |
Correct |
263 ms |
73208 KB |
Output is correct |
50 |
Correct |
214 ms |
42104 KB |
Output is correct |
51 |
Correct |
214 ms |
42232 KB |
Output is correct |
52 |
Correct |
243 ms |
42204 KB |
Output is correct |
53 |
Correct |
206 ms |
40952 KB |
Output is correct |
54 |
Correct |
340 ms |
72828 KB |
Output is correct |
55 |
Correct |
31 ms |
17404 KB |
Output is correct |
56 |
Correct |
20 ms |
16000 KB |
Output is correct |
57 |
Correct |
83 ms |
31612 KB |
Output is correct |
58 |
Correct |
65 ms |
28424 KB |
Output is correct |
59 |
Correct |
103 ms |
45216 KB |
Output is correct |
60 |
Correct |
242 ms |
74872 KB |
Output is correct |
61 |
Correct |
238 ms |
46712 KB |
Output is correct |
62 |
Correct |
207 ms |
43384 KB |
Output is correct |
63 |
Correct |
243 ms |
43256 KB |
Output is correct |
64 |
Correct |
480 ms |
93816 KB |
Output is correct |
65 |
Correct |
464 ms |
94584 KB |
Output is correct |
66 |
Correct |
276 ms |
71032 KB |
Output is correct |
67 |
Correct |
177 ms |
43748 KB |
Output is correct |
68 |
Correct |
364 ms |
62076 KB |
Output is correct |
69 |
Correct |
371 ms |
62700 KB |
Output is correct |
70 |
Correct |
337 ms |
59960 KB |
Output is correct |