제출 #252998

#제출 시각아이디문제언어결과실행 시간메모리
252998Kubin경주 (Race) (IOI11_race)C++17
21 / 100
3043 ms10520 KiB
#include <bits/stdc++.h> using namespace std; vector<vector<pair<size_t, int>>> graph; const int oo = INT_MAX / 3; int& rd(map<int, int>& m, int key) { auto it = m.find(key); if(it == m.end()) it = m.emplace_hint(it, key, +oo); return it->second; } void mini(map<int, int>& m, int key, int value) { rd(m, key) = min(rd(m, key), value); } void dfs_map_paths(size_t u, int s, int d, map<int, int>& m, size_t glock = SIZE_MAX, size_t lock = SIZE_MAX) { if(d > +oo) return; mini(m, s, d); for(auto [v, w] : graph[u]) if(v != lock and v != glock) dfs_map_paths(v, s + w, d + 1, m, glock, u); } int best_path(int _n, int k, int H[][2], int L[]) { const size_t n = _n; graph.resize(n); for(size_t i = 0; i < n - 1; i++) { graph[H[i][0]].emplace_back(H[i][1], L[i]); graph[H[i][1]].emplace_back(H[i][0], L[i]); } int result = +oo; for(size_t f = 0; f < n; f++) { map<int, int> pre = {{0, 0}}; for(auto [v, w] : graph[f]) { map<int, int> cur; dfs_map_paths(v, w, 1, cur, f); for(auto [s, d] : cur) result = min(result, d + rd(pre, k - s)); for(auto [s, d] : cur) mini(pre, s, d); } } return result >= +oo ? -1 : result; } #ifdef XHOVA #define MAX_N 500000 static int N, K; static int H[MAX_N][2]; static int L[MAX_N]; static int solution; inline void my_assert(int e) {if (!e) abort();} void read_input() { int i; my_assert(2==scanf("%d %d",&N,&K)); for(i=0; i<N-1; i++) my_assert(3==scanf("%d %d %d",&H[i][0],&H[i][1],&L[i])); my_assert(1==scanf("%d",&solution)); } int main() { int ans; read_input(); ans = best_path(N,K,H,L); if(ans==solution) printf("Correct.\n"); else printf("Incorrect. Returned %d, Expected %d.\n",ans,solution); return 0; } #endif
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...