Submission #689942

#TimeUsernameProblemLanguageResultExecution timeMemory
689942PatrickRace (IOI11_race)C++17
21 / 100
117 ms7628 KiB
#include "race.h" #include <bits/stdc++.h> using namespace std; typedef long long ll; unordered_map<ll, int> solve(int N, int K, vector<vector<pair<int, int>>>& es, int& curmin, int last, int cur) { // cout << "solve " << cur << "\n"; unordered_map<ll, int> ans; ans.insert({0, 0}); for (auto [next, len] : es[cur]) { if (next == last) continue; unordered_map<ll, int> a = solve(N, K, es, curmin, cur, next); for (auto [k, v] : a) { if (k > K) continue; int search = K - (k + len); auto it = ans.find(search); if (it != ans.end()) { curmin = min(curmin, it->second + v + 1); } } for (auto [k, v] : a) { if (k > K) continue; ans.insert({k + len, v + 1}); } } return ans; } int best_path(int N, int K, int H[][2], int L[]) { // cout << "testcase\n"; vector<vector<pair<int, int>>> es(N); for (int i = 0; i < N - 1; i++) { es[H[i][0]].push_back({H[i][1], L[i]}); es[H[i][1]].push_back({H[i][0], L[i]}); } int curmin = N; auto ans = solve(N, K, es, curmin, -1, 0); if (curmin == N) { return -1; } else { return curmin; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...