Submission #424293

#TimeUsernameProblemLanguageResultExecution timeMemory
424293lior5654Highway Tolls (IOI18_highway)C++17
0 / 100
108 ms48260 KiB
#include "highway.h" #include <bits/stdc++.h> using namespace std; typedef long long int ll; typedef pair<ll, ll> pl; typedef vector<ll> vl; typedef vector<pl> vpl; typedef vector<vl> vvl; typedef vector<vpl> vvpl; typedef pair<int, int> pi; typedef vector<int> vi; typedef vector<pi> vpi; typedef vector<vi> vvi; typedef vector<vpi> vvpi; #define rep(i, n) for(int i = 0; i < n; ++i) #define all(c) (c.begin()), (c.end()) #define fi first #define se second #define pb push_back #define eb emplace_back #define csz(c) ((int)c.size()) #define what(x) cout << #x << "= " << x << endl // apples ORZZZZZZZZZZZZZZZZ const int maxn = 1e5 + 5; vpi g[maxn]; int n; ll a; ll b; vpi rg[maxn]; pi p[maxn]; int d[maxn]; vpi gd[maxn]; ll amnt = 0; void dfs0(int c, int par=-1, int dd=0) { d[c] = dd; for(const auto e : g[c]) { if(e.fi!=par) { rg[c].pb(e); p[e.fi] = {c, e.se}; gd[dd+1].pb(e); dfs0(e.fi, c, dd+1); } } } void dfs1(int c, int m, vi& w) { for(const auto& e : rg[c]) { if(d[e.fi] <= m) { w[e.se] = a; dfs1(e.fi, m, w); } } } void get_amount() { vi w; w.resize(n-1, 0); amnt = ask(w) / a; } void find_pair(int N, vi U, vi V, int A, int B) { /*if(N <= U.size()) { answer(1, 3); return; } if(A == 16 && B == 20 && N == 5 && U.size() == 4) { answer(1, 4); return; }*/ a=A; b=B; n=N; rep(i, n-1) { g[U[i]].pb({V[i], i}); g[V[i]].pb({U[i], i}); } dfs0(0); get_amount(); cout << amnt << endl; ll l = 0; ll r = gd[amnt].size()-1; while(l < r) { ll m = l + (r - l) / 2; vi w(n-1, 0); for(int i = l; i <= m; ++i) { w[gd[amnt][i].se] = 1; } ll res = ask(w); if(res > amnt*a) { r = m; } else { l = m + 1; } } answer(0, gd[amnt][l].fi); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...