Submission #264948

#TimeUsernameProblemLanguageResultExecution timeMemory
264948BasilhijazHighway Tolls (IOI18_highway)C++11
5 / 100
159 ms12448 KiB
#include "highway.h" #include <bits/stdc++.h> using namespace std; vector<vector<pair<int, int> > > adj2(100000); pair<int, int> parents[100000]; bool visited[100000]; void dfs(int s, int parent, int ind){ if(!visited[s]){ parents[s] = {parent, ind}; visited[s] = 1; for(int i = 0; i < adj2[s].size(); i++){ dfs(adj2[s][i].first, s, adj2[s][i].second); } } } void find_pair(int N, std::vector<int> U, std::vector<int> V, int A, int B) { int M = U.size(); vector<int> w(M); for(int i = 0; i < M; i++){ w[i] = 0; } vector<vector<pair<int, int> > > adj(N); for(int i = 0; i < M; i++){ adj2[U[i]].push_back({V[i], i}); adj2[V[i]].push_back({U[i], i}); } dfs(0, 0, 0); for(int i = 1; i < N; i++){ adj[parents[i].first].push_back({i, parents[i].second}); } long long curr = ask(w); int where = 0; bool ok = 1; while(ok){ ok = 0; int lo = 0; int hi = adj[where].size() - 1; int best = -1; while(lo <= hi){ int mid = (lo + hi)/2; for(int j = lo; j <= mid; j++){ w[adj[where][j].second] = !w[adj[where][j].second]; } long long last = ask(w); if(last != curr){ hi = mid - 1; ok = 1; best = adj[where][mid].first; curr = last; } else{ lo = mid + 1; } } if(ok)where = best; } answer(0, where); }

Compilation message (stderr)

highway.cpp: In function 'void dfs(int, int, int)':
highway.cpp:14:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   14 |         for(int i = 0; i < adj2[s].size(); i++){
      |                        ~~^~~~~~~~~~~~~~~~
#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...