Submission #578706

#TimeUsernameProblemLanguageResultExecution timeMemory
578706ogibogi2004Highway Tolls (IOI18_highway)C++14
0 / 100
245 ms262144 KiB
#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)

highway.cpp: In function 'void find_pair(int, std::vector<int>, std::vector<int>, int, int)':
highway.cpp:38:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   38 |         for(int j=0;j<w.size();j++)w[j]=0;
      |                     ~^~~~~~~~~
highway.cpp:52:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   52 |         for(int j=0;j<w.size();j++)w[j]=0;
      |                     ~^~~~~~~~~
highway.cpp:67:28: warning: 't' may be used uninitialized in this function [-Wmaybe-uninitialized]
   67 |     answer(order[s],order[t]);
      |                            ^
highway.cpp:54:26: warning: 's' may be used uninitialized in this function [-Wmaybe-uninitialized]
   54 |         for(int j=mid+1;j<=s;j++)if(parEdge[order[j]]>=0)w[parEdge[order[j]]]=1;
      |                         ~^~~
#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...