Submission #890457

#TimeUsernameProblemLanguageResultExecution timeMemory
890457oblantisRace (IOI11_race)C++17
0 / 100
2 ms9564 KiB
#include <bits/stdc++.h> #include "race.h" //#include <ext/pb_ds/assoc_container.hpp> //#include <ext/pb_ds/tree_policy.hpp> #define all(v) v.begin(), v.end() #define pb push_back #define ss second #define ff first #define vt vector using namespace std; //using namespace __gnu_pbds; 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; //typedef tree< //int, //null_type, //less<int>, //rb_tree_tag, //tree_order_statistics_node_update> //ordered_set; 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; 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]; } } if(ok.find(x) == ok.end())ok[x] = y; else ok[x] = min(ok[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); } } 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]}); } go(0, n); 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...