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"
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> pii;
#define N 90005
vector<int> caras;
vector<pii> grafo[N];
int pai[N], n, id_pai[N];
void dfs(int x, int p){
pai[x]=p;
caras.pb(x);
for(auto v: grafo[x]){
if(v.f == p) continue;
id_pai[v.f] =v.s;
dfs(v.f, x);
}
}
void find_pair(int N_, std::vector<int> U, std::vector<int> V, int A, int B) {
n=N_;
if(sz(U) != n-1) return;
for(int i = 0; i < sz(U); i++){
grafo[U[i]].pb({V[i],i}); grafo[V[i]].pb({U[i],i});
}
dfs(0,0);
int ini = 1, fim = sz(caras)-1,mid,best=-1;
vector<int> w(n-1);
int dist = ask(w)/A;
while(fim >=ini){
mid = (ini + fim)/2;
vector<int> w(n-1);
for(int i = 1; i <= mid; i++) w[id_pai[caras[i]]] = 1;
int dmid = ask(w);
if(dmid == B*dist){
best=mid;
fim=mid-1;
}else ini=mid+1;
}
answer(0, best);
}
# | 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... |