제출 #446435

#제출 시각아이디문제언어결과실행 시간메모리
446435SirCovidThe19th경주 (Race) (IOI11_race)C++14
100 / 100
514 ms87956 KiB
#include <bits/stdc++.h> using namespace std; #define f first #define s second int K, ans = INT_MAX; vector<pair<int, int>> adj[200005]; set<pair<int, int>> S[200005]; void dfs(int i, int p, int dis, int dep){ S[i].insert({dis, dep}); for (auto nxt : adj[i]) if (nxt.f != p){ dfs(nxt.f, i, dis+nxt.s, dep+1); if (S[i].size() < S[nxt.f].size()) swap(S[i], S[nxt.f]); for (auto d : S[nxt.f]){ int other = K+2*dis-d.f; auto x = S[i].lower_bound({other, -1}); if (x != S[i].end() and (*x).f == other) ans = min(ans, d.s+(*x).s-2*dep); }for (auto d : S[nxt.f]) S[i].insert(d); } } int best_path(int n, int k, int h[][2], int l[]){ 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]}); }K = k; dfs(0, 0, 0, 0); return (ans == INT_MAX) ? -1 : ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...