Submission #467234

#TimeUsernameProblemLanguageResultExecution timeMemory
467234Leonardo_PaesHighway Tolls (IOI18_highway)C++17
23 / 100
278 ms9976 KiB
#include "highway.h" #include <bits/stdc++.h> using namespace std; typedef pair<int,int> pii; #define f first #define s second /* ask with a vector saying the edge value (a or b) for each edge to know the smallest dist 1) find an edge in the path S -> T: D&C in the edges, trying to find anyone that is in the path. To do so, just paint everything with A and get the min dist from S to T Then, in the D&C paint all edges at the current set with B, if it changes the distance from S to T, than of these edges is in the path. 2) Let e be an edge in the path S -> T, how to find one of the endpoints, S or T ? multisource bfs from the endpoints of e. Then enumerate the edges according to their distante. Do bb in the prefix of edges, the last one that changes the dist from S to T has S or T as the farthest endpoint. 3) Just do step 2) again */ const int maxn = 9e4 + 10; vector<int> grafo[maxn]; int find_edge(int &n, int &m, vector<int> &u, vector<int> &v, int &a, int &b, int &d){ // log m queries int l = 0, mid, r = m-1; while(l != r){ mid = (l + r) >> 1; vector<int> aux(m, 0); for(int i=0; i<=mid; i++) aux[i] = 1; if(ask(aux) != d) r = mid; else l = mid + 1; } return l; } pii find_endpoints(int &n, int &m, vector<int> &u, vector<int> &v, int &a, int &b, int &d, int &e){ // 2*log m queries pii ans = {0, 0}; vector<int> sbt[2]; queue<pii> fila; fila.push({u[e], 0}); fila.push({v[e], 1}); vector<int> dist(n, 1000000000); dist[u[e]] = dist[v[e]] = 0; while(!fila.empty()){ int x = fila.front().f, y = fila.front().s; fila.pop(); sbt[y].push_back(x); for(int viz : grafo[x]){ if(dist[viz] > dist[x] + 1){ dist[viz] = dist[x] + 1; fila.push({viz, y}); } } } for(int j=0; j<2; j++){ int ini = 0, meio, fim = (int)sbt[j].size() - 1; while(ini != fim){ meio = (ini + fim + 1) >> 1; vector<int> aux(m, 0); vector<bool> mark(n, 0); for(int i=meio; i<sbt[j].size(); i++) mark[sbt[j][i]] = 1; for(int i=0; i<m; i++) if(mark[u[i]] != mark[v[i]]) aux[i] = 1; if(ask(aux) != d) ini = meio; else fim = meio - 1; } if(j) ans.f = sbt[j][ini]; else ans.s = sbt[j][ini]; } return ans; } 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++){ grafo[u[i]].push_back(v[i]); grafo[v[i]].push_back(u[i]); } vector<int> aux(m, 0); // 1 query int d = ask(aux); int e = find_edge(n, m, u, v, a, b, d); pii ans = find_endpoints(n, m, u, v, a, b, d, e); answer(ans.f, ans.s); /* 4 4 1 3 1 3 0 1 0 2 0 3 1 2 */ }

Compilation message (stderr)

highway.cpp: In function 'pii find_endpoints(int&, int&, std::vector<int>&, std::vector<int>&, int&, int&, int&, int&)':
highway.cpp:61:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   61 |    for(int i=meio; i<sbt[j].size(); i++) mark[sbt[j][i]] = 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...