Submission #348489

#TimeUsernameProblemLanguageResultExecution timeMemory
348489juggernautHighway Tolls (IOI18_highway)C++14
0 / 100
27 ms6124 KiB
#include"highway.h" #include<bits/stdc++.h> #ifndef EVAL #include"grader.cpp" #endif using namespace std; vector<pair<int,int>>g[90005]; vector<int>grp[90005]; bool is[90005]; int id[90005],mx,up[90005],under[90005]; long long pivot; void dfs(int v,int p,int depth){ mx=max(mx,depth); if(depth)grp[depth].push_back(id[v]); for(auto to:g[v])if(to.first!=p){ id[to.first]=to.second; up[to.second]=to.first; dfs(to.first,v,depth+1); } } void go(int v,int p,int depth){ for(auto to:g[v])if(to.first!=p){ if(depth+1==pivot)is[to.second]=1; under[to.second]=to.first; go(to.first,v,depth+1); } } void find_pair(int n,vector<int>x,vector<int>y,int a,int b){ for(int i=0;i<n-1;i++){ g[x[i]].push_back({y[i],i}); g[y[i]].push_back({x[i],i}); } vector<int>v(n-1,0); pivot=ask(v); dfs(0,0,0); int l=1,r=mx; while(l<r){ int mid=(l+r+1)>>1; vector<int>(n-1,0); for(int i=l;i<=mid;i++)for(auto to:grp[i])v[to]=1; if(ask(v)!=pivot)l=mid; else r=mid-1; } int uid=l; l=0,r=grp[uid].size()-1; while(l<r){ int mid=(l+r)>>1; vector<int>v(n-1,0); for(int i=l;i<=mid;i++)v[grp[uid][i]]=1; if(ask(v)!=pivot)r=mid; else l=mid+1; } int s=up[grp[uid][l]]; pivot/=a; go(s,s,0); l=0,r=n-2; while(l<r){ int mid=(l+r)>>1; vector<int>v(n-1,0); for(int i=l;i<=mid;i++)v[i]=is[i]; if(ask(v)!=pivot*a)r=mid; else l=mid+1; } answer(s,under[l]); } /* 5 4 1 2 2 4 0 1 0 2 1 3 1 4 */
#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...