이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include "race.h"
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pii;
#define pb push_back
#define f first
#define s second
vector<pii>ad[200000];
map<ll,ll>m[200000];
ll ans = (ll)1e16,x;
void dfs(int node,int parent,int depth,ll cost){
long long t = cost * 2 + x;
m[node][cost] = depth;
for (auto i : ad[node])
if(i.f != parent){
dfs(i.f,node,depth + 1,cost + i.s);
if((int)m[i.f].size() > (int)m[node].size()) m[node].swap(m[i.f]);
for (auto v : m[i.f])
if(m[node].find(t - v.f) != m[node].end())
ans = min(ans,m[node][t - v.f] + v.s - 2 * depth);
for (auto v : m[i.f])
if(m[node].find(v.f) != m[node].end()) m[node][v.f] = min(m[node][v.f],v.s);
else m[node].insert(v);
}
}
int best_path(int N, int K, int H[][2], int L[]){
x = K;
for (int i = 0; i < N - 1;++i){
ad[H[i][0]].push_back({H[i][1],L[i]});
ad[H[i][1]].push_back({H[i][0],L[i]});
}
dfs(0,0,0,0);
return ans == (ll)1e16 ? -1 : ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |