제출 #1161450

#제출 시각아이디문제언어결과실행 시간메모리
1161450JahonaliXRace (IOI11_race)C++20
0 / 100
0 ms320 KiB
#include <bits/stdc++.h> using namespace std; int best_path(int n, int k, int h[][2], int l[]) { int z = n; vector<vector<pair<int, int>>> a(n); for (int i = 0; i + 1 < n; ++i) a[h[i][0]].emplace_back(h[i][1], l[i]), a[h[i][1]].emplace_back(h[i][0], l[i]); vector<int> p(n), w(n); function<void(int)> dfs = [&] (int i) { for (auto [j, z] : a[i]) { if (p[i] != j) { p[j] = i, w[j] = z; dfs(j); } } }; vector<vector<int>> dp(n, vector<int>(k, -1)); dfs(0); for (int i = 0; i < n; ++i) { int x = i, y = 0, f = 0; while (y < k) { if (dp[x][y] == -1) dp[x][y] = f; else dp[x][y] = min(dp[x][y], f); if (dp[x][k - y] != -1) z = min(z, dp[x][k - y] + f); if (!x) break; y += w[x]; x = p[x]; f++; } } if (z == n) z = -1; return z; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...