제출 #866043

#제출 시각아이디문제언어결과실행 시간메모리
866043dpsaveslives경주 (Race) (IOI11_race)C++17
0 / 100
5 ms21336 KiB
#include "race.h" #include <bits/stdc++.h> #define ll long long #define f first #define s second using namespace std; const int MAXN = 2e5+10; vector<pair<ll,ll>> adj[MAXN]; map<ll,ll> help[MAXN]; ll dep[MAXN], dist[MAXN],ans; int k,n; void dfs(int u, int p, int de, ll di){ dep[u] = de; dist[u] = di; help[u][di] = de; for(auto pa : adj[u]){ if(pa.f != p){ dfs(pa.f,u,dep[u]+1,dist[u]+pa.s); } } } void comb(int u, int p){ int tar = k+2*dist[u]; for(auto pa : adj[u]){ int v = pa.f; if(v != p){ comb(v,u); if(help[v].size() > help[u].size()) swap(help[v],help[u]); for(auto x : help[v]){ if(help[u].find(tar-x.f) != help[u].end()){ ans = min(ans,help[u][tar-x.f]+x.s-2*dep[u]); } } for(auto x : help[v]){ if(help[u].find(x.f) != help[u].end()){ help[u][x.f] = min(help[u][x.f],x.s); } else{ help[u].insert(x); } } } } } int best_path(int N, int K, int H[][2], int L[]){ for(int i = 0;i<N;++i){ int u = H[i][0], v = H[i][1], w = L[i]; adj[u].push_back({v,w}); adj[v].push_back({u,w}); } dfs(0,-1,0,0); n = N; k = K; ans = INT_MAX; comb(0,-1); if(ans != INT_MAX) return ans; else return -1; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...