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;
// macros
typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef pair<ll, ll> lll;
typedef tuple<int, int, int> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<iii> viii;
typedef vector<ll> vll;
typedef vector<lll> vlll;
#define REP(a,b,c) for(int a=int(b); a<int(c); a++)
#define RE(a,c) REP(a,0,c)
#define RE1(a,c) REP(a,1,c+1)
#define REI(a,b,c) REP(a,b,c+1)
#define REV(a,b,c) for(int a=int(c-1); a>=int(b); a--)
#define FOR(a,b) for(auto& a : b)
#define all(a) a.begin(), a.end()
#define pb push_back
#define popb pop_back
#define fi first
#define se second
const int MX = 2e5;
int n, m;
vi U, V, W;
vi adj[MX];
ll normal;
vi seq;
bitset<MX> visited;
void fillAdj() {
RE(i,U.size()) {
adj[U[i]].push_back(i);
adj[V[i]].push_back(i);
}
}
void bfsSequence(vi init) {
seq.clear();
queue<int> q;
visited.reset();
FOR(u,init) q.push(u), visited[u]=1;
while(!q.empty()) {
int u=q.front(); q.pop();
seq.push_back(u);
FOR(e,adj[u]) {
if(visited[U[e]] && visited[V[e]]) continue;
if(V[e] == u) swap(U[e], V[e]);
int v=V[e];
q.push(v); visited[v] = 1;
}
}
}
int binarySearchSeq() {
int lb=0, ub=n-1;
while(lb != ub) {
int mid=(lb+ub)/2;
W.assign(m,1);
REP(i,0,mid+1) W[seq[i]] = 0;
if(ask(W) == normal) ub=mid;
else lb=mid+1;
}
return V[seq[lb]];
}
int getEdgeOnPath() {
int lb=0, ub=m-1;
while(lb != ub) {
int mid=(lb+ub)/2;
W.assign(m,0);
RE(i,mid+1) W[i] = 1;
if(ask(W) == normal) lb=mid+1;
else ub=mid;
}
return lb;
}
void find_pair(int N, vi _U, vi _V, int A, int B) {
n=N; U=_U; V=_V; m=U.size();
fillAdj();
W.assign(m,0);
normal = ask(W);
int onPath = getEdgeOnPath();
int v1 = U[onPath], v2 = V[onPath];
bfsSequence({v1, v2});
int s = binarySearchSeq();
bfsSequence({s});
int t = binarySearchSeq();
answer(s,t);
}
| # | 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... |