Submission #1024987

#TimeUsernameProblemLanguageResultExecution timeMemory
1024987dostsRace (IOI11_race)C++17
100 / 100
287 ms79184 KiB
#include "race.h" //Dost SEFEROĞLU #include <bits/stdc++.h> using namespace std; #define int long long #define pii pair<int,int> #define ff first #define ss second #define sp << " " << #define vi vector<int> #define all(xx) xx.begin(),xx.end() #define ps(xxx) cout << (xxx) << endl; const int LIM = 2e5+1,inf = 1e18; vector<pii> edges[LIM]; map<int,int> s[LIM]; int ans = inf; int k; void dfs(int node,int p,int d = 0,int dep = 0) { for (auto it : edges[node]) if (it.ss != p) dfs(it.ss,node,d+it.ff,dep+1); s[node][d] = dep; for (auto it : edges[node]) { if (it.ss == p) continue; if (s[it.ss].size() > s[node].size()) s[it.ss].swap(s[node]); for (auto it : s[it.ss]) { if (s[node].count(k+2*d-it.ff)) { ans = min(ans,it.ss+s[node][k+2*d-it.ff]-2*dep); } } for (auto it : s[it.ss]) { if (s[node].count(it.ff)) s[node][it.ff] = min(s[node][it.ff],it.ss); else s[node][it.ff] = it.ss; if (it.ff == k+d) { ans = min(ans,it.ss-dep); } } s[it.ss].clear(); } } int32_t best_path(int32_t N, int32_t K, int32_t H[][2], int32_t L[]) { k = K; for (int i=0;i<N-1;i++) { edges[H[i][0]].push_back({L[i],H[i][1]}); edges[H[i][1]].push_back({L[i],H[i][0]}); } dfs(0,0); if (ans == inf) return -1; return 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...