# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
578706 | ogibogi2004 | Highway Tolls (IOI18_highway) | C++14 | 245 ms | 262144 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "highway.h"
#include<bits/stdc++.h>
using namespace std;
const int MAXN=9e4+6;
vector<pair<int,int> >g[MAXN];
int par[MAXN];
int parEdge[MAXN];
vector<int>order;
void dfs(int u,int p)
{
order.push_back(u);
for(auto xd:g[u])
{
if(xd.first==p)continue;
par[xd.first]=u;
parEdge[xd.first]=xd.second;
dfs(xd.first,u);
order.push_back(u);
}
}
void find_pair(int N, vector<int> U, vector<int> V, int A, int B) {
int M = U.size();
for(int i=0;i<M;i++)
{
g[U[i]].push_back({V[i],i});
g[V[i]].push_back({U[i],i});
}
parEdge[0]=-1;
dfs(0,-1);
int low=0,high=order.size()-1,s,t;
int dist;
vector<int>w;
for(int i=0;i<M;i++)w.push_back(0);
dist=(long long)ask(w)/A;
while(low<=high)
{
int mid=(low+high)/2;
for(int j=0;j<w.size();j++)w[j]=0;
for(int j=0;j<=mid;j++)if(parEdge[order[j]]>=0)w[parEdge[order[j]]]=1;
int cntheavy=(long long)(ask(w)-dist*A)/(B-A);
if(cntheavy==dist)
{
s=mid;
high=mid-1;
}
else low=mid+1;
}
low=0;high=order.size()-1;
while(low<=high)
{
int mid=(low+high)/2;
for(int j=0;j<w.size();j++)w[j]=0;
if(mid<=s&&par[order[mid]]==order[mid+1])w[parEdge[order[mid]]]=1;
for(int j=mid+1;j<=s;j++)if(parEdge[order[j]]>=0)w[parEdge[order[j]]]=1;
int cntheavy=(long long)(ask(w)-dist*A)/(B-A);
if(cntheavy==dist)
{
t=mid;
low=mid+1;
}
else high=mid-1;
}
/*for(auto xd:order)cout<<xd<<" ";
cout<<endl;
cout<<s<<" "<<t<<endl;
cout<<order[s]<<" "<<order[t]<<endl;*/
answer(order[s],order[t]);
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |