Submission #438942

#TimeUsernameProblemLanguageResultExecution timeMemory
438942leinad2Highway Tolls (IOI18_highway)C++17
7 / 100
286 ms11108 KiB
#include "highway.h" #include<bits/stdc++.h> using namespace std; vector<pair<int, int> >adj[90010]; int vis[90010]; void find_pair(int N, vector<int>U, vector<int>V, int A, int B) { int M=U.size(); vector<int>w(M);long long X=ask(w); for(int i=0;i<M;i++) { adj[U[i]].push_back({V[i], i}); adj[V[i]].push_back({U[i], i}); } int s=0;int e=M-1; while(s<e) { int m=s+e>>1; for(int i=0;i<M;i++)w[i]=0; for(int i=0;i<=m;i++)w[i]=1; if(ask(w)>X)e=m; else s=m+1; } int S=U[s], E=V[s]; queue<pair<int, int> >q; q.push({S, 0}); q.push({E, 1}); vis[S]=vis[E]=1; vector<pair<int, int> >v1, v2; while(q.size()) { int a=q.front().first;int b=q.front().second;q.pop(); for(int i=0;i<adj[a].size();i++) { int p=adj[a][i].first; if(vis[p])continue; vis[p]=1;q.push({p, b}); if(b==0)v1.push_back(adj[a][i]); else v2.push_back(adj[a][i]); } } int ans1; if(v1.size()) { int a=0;int b=v1.size()-1; while(a<b) { int m=a+b+1>>1; for(int i=0;i<M;i++)w[i]=0; for(int i=m;i<=b;i++)w[v1[i].second]=1; if(ask(w)>X)a=m; else b=m-1; } ans1=v1[a].first; } else ans1=S; int ans2; if(v2.size()) { int a=0;int b=v2.size()-1; while(a<b) { int m=a+b+1>>1; for(int i=0;i<M;i++)w[i]=0; for(int i=m;i<=b;i++)w[v2[i].second]=1; if(ask(w)>X)a=m; else b=m-1; } ans2=v2[a].first; } else ans2=E; answer(ans1, ans2); }

Compilation message (stderr)

highway.cpp: In function 'void find_pair(int, std::vector<int>, std::vector<int>, int, int)':
highway.cpp:18:16: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   18 |         int m=s+e>>1;
      |               ~^~
highway.cpp:33:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   33 |         for(int i=0;i<adj[a].size();i++)
      |                     ~^~~~~~~~~~~~~~
highway.cpp:48:22: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   48 |             int m=a+b+1>>1;
      |                   ~~~^~
highway.cpp:63:22: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   63 |             int m=a+b+1>>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...