This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define all(x) x.begin(),x.end()
long long ask(const std::vector<int> &w);
void answer(int s, int t);
void find_pair(int N, std::vector<int> U, std::vector<int> V, int A, int B) {
vector<vector<pair<int,int>>> adj(N);
for(int i=0;i<U.size();i++){
adj[U[i]].emplace_back(V[i],i);
adj[V[i]].emplace_back(U[i],i);
}
vector<int> pedge(N);
vector<int> depth(N);
function<void(int,int,int,int)> dfs = [&](int x,int p,int dep,int par){
depth[x]=dep;
pedge[x]=par;
for(auto&i:adj[x])if(i.first!=p)dfs(i.first,x,dep+1,i.second);
};
dfs(0,-1,0,-1);
int M = U.size();
auto base = ask(vector<int>(M));
auto basedep = base/((long long)A);
vector<int> sus;
for(int i=0;i<N;i++)if(depth[i]==basedep)sus.emplace_back(i);
while(sus.size()>1){
int mid = (sus.size())/2;
vector<int> left,right;
for(int i=0;i<mid;i++)left.emplace_back(sus[i]);
for(int i=mid;i<sus.size();i++)right.emplace_back(sus[i]);
vector<int> w(M);
for(int&i:left)w[pedge[i]]=1;
auto ans = ask(w);
if(ans!=base)sus=left;
else sus=right;
}
answer(0, sus[0]);
}
Compilation message (stderr)
highway.cpp: In function 'void find_pair(int, std::vector<int>, std::vector<int>, int, int)':
highway.cpp:11:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
11 | for(int i=0;i<U.size();i++){
| ~^~~~~~~~~
highway.cpp:32:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
32 | for(int i=mid;i<sus.size();i++)right.emplace_back(sus[i]);
| ~^~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |