제출 #1323794

#제출 시각아이디문제언어결과실행 시간메모리
1323794Trisanu_Das경주 (Race) (IOI11_race)C++17
0 / 100
7 ms14392 KiB
#include <bits/stdc++.h> #include "race.h" using namespace std; #define ff first #define ss second int K, ans = INT_MAX; vector<pair<int, int>> adj[200005]; set<pair<int, int>> S[200005]; void dfs(int u, int par, int dist, int depth) { S[u].insert({dist, depth}); for(auto v : adj[u]){ if(v.ff != par){ dfs(v.ff, u, dist + v.ss, depth + 1); if(S[u].size() < S[v.ff].size()) swap(S[u], S[v.ff]); for(auto d : S[v.ff]){ int o = K + 2 * dist - d.ff; auto x = S[u].lower_bound({o, -1}); if(x != S[u].end() && (*x).ff == o) ans = min(ans, d.ss + (*x).ss - 2 * depth); } for(auto d : S[v.ff]) S[u].insert(d); } } } int best_path(int n, int k, int h[][2], int l[]) { k = K; 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...