Submission #727276

#TimeUsernameProblemLanguageResultExecution timeMemory
727276colossal_pepeRace (IOI11_race)C++17
21 / 100
3054 ms20120 KiB
#include "race.h" #include <iostream> #include <vector> #include <map> using namespace std; int n, k, ans = 1e9; vector<vector<pair<int, int>>> g; map<int, int> dfs(int u, int par, int s, int d) { map<int, int> ret; ret[s] = d; for (auto [v, w] : g[u]) { if (v == par) continue; map<int, int> res = dfs(v, u, s + w, d + 1); if (ret.size() > res.size()) swap(ret, res); for (auto [sv, dv] : res) { int su = k - (sv - 2 * s); if (ret.find(su) != ret.end()) ans = min(ans, dv + ret[su] - 2 * d); } for (auto [sv, dv] : res) { if (ret.find(sv) != ret.end()) ret[sv] = min(ret[sv], dv); else ret[sv] = dv; } } return ret; } int best_path(int N, int K, int H[][2], int L[]) { n = N; k = K; g.resize(n); for (int i = 0; i < n - 1; i++) { g[H[i][0]].push_back({H[i][1], L[i]}); g[H[i][1]].push_back({H[i][0], L[i]}); } dfs(0, 0, 0, 0); return (ans > n ? -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...