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;
#define all(x) x.begin(), x.end()
#define ar array
#define pb push_back
#define ln '\n'
//#define int long long
using i64 = long long;
template <class F, class _S>
bool chmin(F &u, const _S &v){
bool flag = false;
if ( u > v ){
u = v; flag |= true;
}
return flag;
}
template <class F, class _S>
bool chmax(F &u, const _S &v){
bool flag = false;
if ( u < v ){
u = v; flag |= true;
}
return flag;
}
void find_pair(int N, std::vector<int> U, std::vector<int> V, int A, int B) {
int n = N, M = U.size();
vector <vector<ar<int,2>>> adj(n);
for ( int i = 0; i < M; i++ ){
adj[U[i]].pb({V[i], i});
adj[V[i]].pb({U[i], i});
}
vector <int> w(M);
i64 C = ask(w);
int l = 0, r = n - 1;
while ( l < r ){
int m = (l + r) / 2;
w.assign(M, 0);
for ( int u = m + 1; u < n; u++ ){
for ( auto &[v, j]: adj[u] ){
w[j] = 1;
}
}
if ( ask(w) == C ){
r = m;
} else l = m + 1;
}
vector <int> fa(n), ls, us(n);
queue <int> q;
q.push(l); us[l] = 1;
while ( !q.empty() ){
int u = q.front();
q.pop();
ls.pb(u);
for ( auto &[v, j]: adj[u] ){
if ( us[v] ) continue;
us[v] = 1;
fa[v] = u;
q.push(v);
}
}
vector <int> e(n, -1);
for ( int u = 0; u < n; u++ ){
for ( auto &[v, j]: adj[u] ){
if ( fa[u] == v ){
e[u] = j;
}
}
}
int root = l;
l = 1, r = n - 1;
while ( l < r ){
int m = (l + r) / 2;
w.assign(M, 1);
for ( int i = 1; i <= m; i++ ){
w[e[ls[i]]] = 0;
}
if ( ask(w) == C ){
r = m;
} else l = m + 1;
}
int sx = ls[l];
vector <int> pth;
{ // path from sx to root
int it = sx;
while ( it != root ){
pth.pb(e[it]);
it = fa[it];
}
}
l = 0, r = n - 1;
while ( l < r ){
int m = (l + r) / 2;
w.assign(M, 1);
for ( auto &j: pth ) w[j] = 0;
for ( int i = 0; i < m; i++ ){
w[e[ls[i + 1]]] = 0;
}
if ( ask(w) == C ){
r = m;
} else l = m + 1;
}
int se = ls[l];
answer(sx, se);
}
# | 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... |