제출 #1319789

#제출 시각아이디문제언어결과실행 시간메모리
1319789yessimkhan경주 (Race) (IOI11_race)C++20
21 / 100
177 ms54768 KiB
#include <bits/stdc++.h> // solved by bekagg #define ll long long #define ent '\n' #define pb push_back #define all(x) x.begin(),x.end() #define PRaim_bek_abi ios_base::sync_with_stdio(0);cin.tie(0); using namespace std; const int N = 2e5+5; const int MOD = 1e9+7; int d[N] , t[N] , ans = INT_MAX , dist; vector< pair<int , int> >g[N]; map<int,int> mp[N]; void dfs(int v , int p){ mp[v][t[v]] = d[v]; for (auto [to , c] : g[v]){ if (to == p) continue; d[to] = d[v] + 1; t[to] = t[v] + c; dfs(to , v); if (mp[v].size() < mp[to].size()){ swap(mp[to] , mp[v]); } for (auto [too , c] : mp[to]){ if (c == 0 or mp[v][(dist - too + 2 * t[v])] == 0) continue; ans = min(ans , mp[v][(dist - too + 2 * t[v])] + c - 2 * d[v]); } for (auto [too , c] : mp[to]){ if (c == 0) continue; if (mp[v][too] == 0) mp[v][too] = c; else mp[v][too] = min(mp[v][too] , c); } } // to2 - d[v] = k - (to1 - d[v]) // to2 - d[v] = k - to1 + d[v] // to2 = k - to1 + 2 * d[v] } int best_path(int n , int k , int h[][2] , int l[]){ dist = k; for (int i = 0; i < n - 1; i++){ g[h[i][0]].pb({h[i][1] , l[i]}); g[h[i][1]].pb({h[i][0] , l[i]}); } d[1] = 1; dfs(1 , 0); return (ans == INT_MAX ? -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...