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 "highway.h"
#include <bits/stdc++.h>
using namespace std;
struct node {
int p;
vector<pair<node*, int>> l;
int d;
};
void dfs(node* n, node* p, int d){
n->d = d;
for(auto [c,x] : n->l){
if(c==p) continue;
c->p = x;
dfs(c, n, d+1);
}
}
void find_pair(int N, std::vector<int> U, std::vector<int> V, int A, int B) {
node g[N];
int m = U.size();
for(int i = 0;i < U.size();i++){
g[U[i]].l.emplace_back(&g[V[i]], i);
g[V[i]].l.emplace_back(&g[U[i]], i);
}
dfs(&g[0], NULL, 0);
vector<int> w(m, 0);
long long dis = ask(w)/A;
vector<pair<int, int>> v;
for(int i = 1;i < N;i++) if(g[i].d == dis) v.emplace_back(g[i].p, i);
int l = 0, r = v.size()-1, mid;
while(l<r){
mid = l+r>>1;
for(int i = l;i <= mid;i++) w[v[i].first] = 1;
long long re = ask(w);
for(int i = l;i <= mid;i++) w[v[i].first] = 0;
if(re > dis*A){
r = mid;
} else l = mid+1;
}
answer(0, v[l].second);
}
Compilation message (stderr)
highway.cpp: In function 'void find_pair(int, std::vector<int>, std::vector<int>, int, int)':
highway.cpp:20:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
20 | for(int i = 0;i < U.size();i++){
| ~~^~~~~~~~~~
highway.cpp:31:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
31 | mid = l+r>>1;
| ~^~
# | 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... |