#include <bits/stdc++.h>
using namespace std;
const int nmax=2e5+3;
vector <pair <int, int> > v[nmax];
map <int, int> m[nmax];
int k, ans=nmax;
void dfs(int nod, int parent, int d, int h)
{
m[nod][d]=h;
for(auto [i, cost]:v[nod])
{
if(i!=parent)
{
dfs(i, nod, d+cost, h+1);
if(m[i].size()>m[nod].size()) swap(m[i], m[nod]);
for(auto [dist, he]:m[i])
{
int caut=k-(dist+2*d);
if(m[nod].count(caut))
{
ans=min(ans, he+m[nod][caut]-2*h);
}
}
for(auto [dist, he]:m[i])
{
if(m[nod].count(dist))
{
m[nod][dist]=min(m[nod][dist], he);
}
else m[nod][dist]=he;
}
}
}
}
long long best_path(int n, int k, int h[][2], int l[])
{
::k=k;
for(int i=0; i<n-1; i++)
{
int a=h[i][0], b=h[i][1];
v[a].push_back({b, l[i]});
v[b].push_back({a, l[i]});
}
dfs(0, -1, 0, 1);
if(ans==nmax) return -1;
return ans;
}
Compilation message
race.cpp: In function 'void dfs(int, int, int, int)':
race.cpp:13:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
13 | for(auto [i, cost]:v[nod])
| ^
race.cpp:19:22: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
19 | for(auto [dist, he]:m[i])
| ^
race.cpp:27:22: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
27 | for(auto [dist, he]:m[i])
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
6 ms |
14428 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
6 ms |
14428 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
6 ms |
14428 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
6 ms |
14428 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |