Submission #890575

#TimeUsernameProblemLanguageResultExecution timeMemory
890575oblantisRace (IOI11_race)C++17
0 / 100
2 ms9780 KiB
#include <bits/stdc++.h> #include "race.h" #define all(v) v.begin(), v.end() #define pb push_back #define ss second #define ff first #define vt vector using namespace std; typedef long long ll; typedef vector<int> vi; typedef vector<ll> vll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef pair<double, int> pdi; const ll inf = 1e9 + 10000; const int mod = 1e9+7; const int maxn = 2e5 + 12; vector<pii> g[maxn]; int sz[maxn], ans = maxn, k; bool was[maxn]; void dfs(int v, int pr) { sz[v] = 1; for(auto i : g[v]) { if(!was[i.ff] && i.ff != pr) { dfs(i.ff, v); sz[v] += sz[i.ff]; } } } int fnd(int v, int pr, int n) { for(auto i : g[v]) { if(!was[i.ff] && i.ff != pr){ if(sz[i.ff] > n / 2) { return fnd(i.ff, v, n); } } } return v; } map<int, int> ok; vector<pii> upd; void cnt(int v, int pr, int x, int y) { if(x <= k){ if(ok.find(k - x) != ok.end())ans = min(ans, ok[k - x] + y); } else x = k + 1; sz[v] = 1; for(auto i : g[v]) { if(i.ff != pr && !was[i.ff]) { cnt(i.ff, v, x + i.ss, y + 1); sz[v] += sz[i.ff]; } } upd.pb({x, y}); } void go(int v, int n) { dfs(v, -1); int cen = fnd(v, -1, n); was[cen] = 1; ok.clear(); ok[0] = 0; for(auto i : g[cen]){ if(!was[i.ff]){ cnt(i.ff, cen, i.ss, 1); while(!upd.empty()){ if(upd.back().ff <= k) { if(ok.find(upd.back().ff) == ok.end())ok[upd.back().ff] = upd.back().ss; else ok[upd.back().ff] = min(ok[upd.back().ff], upd.back().ss); } upd.pop_back(); } } } for(auto i : g[cen]){ if(!was[i.ff]){ go(i.ff, sz[i.ff]); } } } int best_path(int n, int K, int h[][2], int l[]){ k = K; for(int i = 0; i < n; i++ ){ g[h[i][0]].pb({h[i][1], l[i]}); g[h[i][1]].pb({h[i][0], l[i]}); } if(K == 0)ans = 0; go(0, n); return (ans == maxn ? -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...