Submission #103105

#TimeUsernameProblemLanguageResultExecution timeMemory
103105daniel920712Highway Tolls (IOI18_highway)C++14
100 / 100
334 ms30368 KiB
#include <iostream> #include <stdio.h> #include <stdlib.h> #include <vector> #include <utility> #include <queue> #include "highway.h" using namespace std; vector < int > how; vector < pair < int , int > > a,b; vector < pair < int , int > > road[900005]; int n,m,x=-1,y=-1; long long t; bool have_V[900005]={0}; bool have_E[1300005]={0}; int F(int l,int r) { if(l==r) return l; int i; for(i=0;i<=(l+r)/2;i++) how[i]=1; if(ask(how)>t) { for(i=0;i<=(l+r)/2;i++) how[i]=0; return F(l,(l+r)/2); } else { for(i=0;i<=(l+r)/2;i++) how[i]=0; return F((l+r)/2+1,r); } } int Ans1(int l,int r) { int i; if(l==r) return a[l].second; for(i=(l+r)/2+1;i<=r;i++) how[a[i].first]=1; if(ask(how)==t) { for(i=(l+r)/2+1;i<=r;i++) how[a[i].first]=0; return Ans1(l,(l+r)/2); } else { for(i=(l+r)/2+1;i<=r;i++) how[a[i].first]=0; return Ans1((l+r)/2+1,r); } } int Ans2(int l,int r) { int i; if(l==r) return b[l].second; for(i=(l+r)/2+1;i<=r;i++) how[b[i].first]=1; if(ask(how)==t) { for(i=(l+r)/2+1;i<=r;i++) how[b[i].first]=0; return Ans2(l,(l+r)/2); } else { for(i=(l+r)/2+1;i<=r;i++) how[b[i].first]=0; return Ans2((l+r)/2+1,r); } } void find_pair(int N,vector < int > U,vector < int > V,int A,int B) { int i,edge,here,x; n=N; m=U.size(); for(i=0;i<m;i++) how.push_back(0); for(i=0;i<m;i++) { road[U[i]].push_back(make_pair(V[i],i)); road[V[i]].push_back(make_pair(U[i],i)); } t=ask(how); edge=F(0,m-1); have_V[U[edge]]=1; have_V[V[edge]]=1; have_E[edge]=1; a.push_back(make_pair(edge,U[edge])); b.push_back(make_pair(edge,V[edge])); queue < pair < int , int > > temp; temp.push(make_pair(U[edge],0)); temp.push(make_pair(V[edge],1)); while(!temp.empty()) { here=temp.front().first; x=temp.front().second; temp.pop(); for(auto i:road[here]) { if(!have_V[i.first]) { have_V[i.first]=1; have_E[i.second]=1; temp.push(make_pair(i.first,x)); if(x) b.push_back(make_pair(i.second,i.first)); else a.push_back(make_pair(i.second,i.first)); } } } for(i=0;i<m;i++) { if(!have_E[i]) { //printf("%d\n",i); how[i]=1; } } x=Ans1(0,a.size()-1); y=Ans2(0,b.size()-1); answer(x,y); }
#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...