Submission #1068232

#TimeUsernameProblemLanguageResultExecution timeMemory
1068232KiprasRace (IOI11_race)C++17
21 / 100
3083 ms27988 KiB
#include <bits/stdc++.h> typedef long long ll; using namespace std; constexpr ll maxN = 2e5+10; constexpr ll inf = 1e15; vector<pair<ll, ll>> adj[maxN]; ll res = inf, k; map<ll, ll> dfs(ll v, ll p, ll konst, ll dep) { map<ll, ll> mp; mp[konst]=dep; for(auto i : adj[v]) { if(i.first==p)continue; map<ll, ll> tmp = dfs(i.first, v, i.second+konst, dep+1); if(tmp.size()<mp.size())swap(mp, tmp); for(auto x : tmp) { ll val = x.first; ll dep1 = x.second; ll needed = k+2*konst-val; if(mp.count(needed)) { ll dep2 = mp[needed]; res=min(res, dep1+dep2-2*dep); } } for(auto x : tmp) { if(!mp.count(x.first))mp[x.first]=x.second; else mp[x.first]=min(x.second, mp[x.first]); } } return mp; } int best_path(int N, int K, int H[][2], int L[]) { k=K; for(int i = 0; i < N-1; i++) { ll aa = H[i][0], bb = H[i][1]; adj[aa].push_back({bb, L[i]}); adj[bb].push_back({aa, L[i]}); } dfs(0, -1, 0, 0); if(res==inf) { return -1; } return res; } /*int nn, kk; int H[maxN][2]; int L[maxN]; int solution; int main() { cin>>nn>>kk; for(int i = 0; i < nn-1; i++) { cin>>H[i][0]>>H[i][1]; } for(int i = 0; i < nn-1; i++) { cin>>L[i]; } cout<<best_path(nn,kk,H,L); return 0; } */
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...