Submission #1058362

#TimeUsernameProblemLanguageResultExecution timeMemory
1058362ReLiceHighway Tolls (IOI18_highway)C++17
100 / 100
142 ms28820 KiB
#include "highway.h" #include <bits/stdc++.h> #define ll long long #define vll vector<ll> #define pb push_back #define pf push_front #define sz size() #define bc back() #define pob pop_back() #define pof pop_front() #define fr first #define sc second using namespace std; const ll N=2e5+7; const ll inf=1e18; vector<vector<array<ll,2>>> g(N), g2(N); void find_pair(int N, std::vector<int> U, std::vector<int> V, int A, int B) { ll M = V.sz; ll s, t, rt; ll n = N; vll v, u; ll i; for(auto i : V) v.pb(i); for(auto i : U) u.pb(i); vector<int> w(M, 0); ll x = ask(w); for(i=0;i<M;i++){ g[v[i]].pb({u[i], i}); g[u[i]].pb({v[i], i}); } {//getting vertex on the path int l = 0, r = n - 1, ans; while ( l <= r ){ int m = (l + r) / 2; if ( r - l > 60000 ) m = 60000; w.assign(M, 0); for ( int u = m + 1; u < n; u++ ){ for ( auto &[v, j]: g[u] ){ w[j] = 1; } } if ( ask(w) == x ){ ans = m; r = m - 1; } else l = m + 1; } rt = ans; } vll p(n), d(n); vll pr(n), tour; vector<vll> dd(n); auto bfs = [&](ll s){ for(i=0;i<n;i++){ dd[i].clear(); d[i] = inf; pr[i] = p[i] = -1; } queue<ll> q; q.push(s); d[s] = 0; while(q.size()){ ll x = q.front(); q.pop(); dd[d[x]].pb(x); for(auto [to, r] : g[x]){ if(d[to] > d[x] + 1){ d[to] = d[x] + 1 ; pr[to] = r; p[to] = x; q.push(to); } } } tour.clear(); for(i=0;i<n;i++){ for(auto j : dd[i]) tour.pb(j); } }; vll path; auto calc = [&](ll n){ ll l = 0, r = n; while(l + 1 < r){ ll m = (l + r) / 2; if(r - l > 60000) m = 60000; w.assign(M, 1); for(auto i : path) w[i] =0; //~ cout<<m<<endl; for(i=1;i<m;i++) { w[pr[tour[i]]] = 0; //~ cout<<v[pr[tour[i]]]<<' '<<u[pr[tour[i]]]<<endl; } ll y = ask(w); if(x == y) r = m; else l = m; } return r - 1; }; bfs(rt); ll l = 1, r = n - 1; ll ans; while ( l <= r ){ int m = (l + r) / 2; if ( r - l > 60000 ) m = 60000; w.assign(M, 1); for ( int i = 1; i <= m; i++ ){ w[pr[tour[i]]] = 0; } if ( ask(w) == x ){ ans = m; r = m - 1; } else l = m + 1; } s = tour[ans]; { ll x = s; while(x != rt){ path.pb(pr[x]); x = p[x]; } } l = 0, r = ans - 1; while ( l <= r ){ int m = (l + r) / 2; w.assign(M, 1); for ( auto &j: path ) w[j] = 0; for ( int i = 0; i < m; i++ ){ w[pr[tour[i + 1]]] = 0; } if ( ask(w) == x ){ ans = m; r = m - 1; } else l = m + 1; } t = tour[ans]; answer(s, t); }

Compilation message (stderr)

highway.cpp: In function 'void find_pair(int, std::vector<int>, std::vector<int>, int, int)':
highway.cpp:99:7: warning: variable 'calc' set but not used [-Wunused-but-set-variable]
   99 |  auto calc = [&](ll n){
      |       ^~~~
highway.cpp:147:14: warning: 'ans' may be used uninitialized in this function [-Wmaybe-uninitialized]
  147 |  s = tour[ans];
      |              ^
highway.cpp:58:6: warning: 'ans' may be used uninitialized in this function [-Wmaybe-uninitialized]
   58 |   rt = ans;
      |   ~~~^~~~~
#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...