제출 #1000807

#제출 시각아이디문제언어결과실행 시간메모리
1000807ALTAKEXE경주 (Race) (IOI11_race)C++17
0 / 100
1 ms2392 KiB
#include <bits/stdc++.h> using namespace std; vector<pair<int, int>> adj[1010]; vector<vector<pair<int, int>>> x; int dp[200001][101] = {INT_MAX}; int _N, _K, mn = INT_MAX; void dfs(int v, int p = -1) { dp[v][0] = 0; for (auto [i, w] : adj[v]) { if (i != p) dfs(i, v); } x.assign(_K + 1, {}); for (auto [i, w] : adj[v]) { if (i == p) continue; for (int j = w; j <= _K; j++) { if (dp[i][j - w] == INT_MAX) continue; if (x[j].size() < 2) x[j].push_back({dp[i][j - w] + 1, i}); else if (dp[i][j - w] + 1 < x[j][1].first) x[j][1] = {dp[i][j - w] + 1, i}; dp[v][j] = min(dp[v][j], dp[i][j - w] + 1); } } if (!x[_K].empty()) mn = min(mn, x[_K][0].first); for (int i = 1; i < _K; i++) { if (x[i].empty() || x[_K - i].empty()) continue; if (x[i][0].second != x[_K - i][0].second) mn = min(mn, x[i][0].first + x[_K - i][0].first); else if (1 < x[_K - i].size()) mn = min(mn, x[i][0].first + x[_K - i][1].first); } } int best_path(int n, int k, int h[][2], int l[]) { _N = n; _K = k; for (int i = 0; i < n - 1; i++) { adj[h[i][0] + 1].emplace_back(h[i][1] + 1, l[i]); adj[h[i][1] + 1].emplace_back(h[i][0] + 1, l[i]); } dfs(0); if (mn == INT_MAX) return -1; else return mn; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...