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 MAX_N 90004
int n ,m;
vector <pair <int ,int>> adj[MAX_N];
vector <pair<int ,int>> nodes;
void bfs(int s ,int f){
nodes.clear();
queue <pair<int,int>> nxt;
nxt.push({s ,f});
while(!nxt.empty()){
int u = nxt.front().first ,f = nxt.front().second; nxt.pop();
nodes.push_back({u ,f});
for(auto e : adj[u])
nxt.push(e);
}
}
vector <int> main_W;
int solve(int u ,int f ,long long dist){
bfs(u ,f);
int st = 0 ,en = nodes.size()-1 ,mid;
while(st < en){
mid = (st+en+1)>>1;
vector <int> w = main_W;
for(int i=mid; i<=en; i++)
w[nodes[i].second] = 1;
if(ask(w) != dist)
st = mid;
else
en = mid-1;
}
return nodes[st].first;
}
vector <pair<int ,int>> t_adj[MAX_N];
void get_bfs_tree(int s){
main_W.resize(m ,1);
vector <bool> vis(n); vis[s] = 1;
queue <int> nxt; nxt.push(s);
while(!nxt.empty()){
int u = nxt.front(); nxt.pop();
for(auto e : adj[u])
if(!vis[e.first]){
vis[e.first] = 1;
nxt.push(e.first);
main_W[e.second] = 0;
t_adj[u].push_back(e);
}
}
for(int i=0; i<n; i++)
swap(adj[i] ,t_adj[i]);
}
void find_pair(int N, std::vector<int> U, std::vector<int> V, int A, int B) {
n = N ,m = U.size();
for(int i=0; i<m; i++)
adj[U[i]].push_back({V[i] ,i}),
adj[V[i]].push_back({U[i] ,i});
vector <int> w(m ,0);
long long dist = ask(w);
int st = 0 ,en = m-1 ,mid;
while(st < en){
mid = (st+en)>>1;
for(int i=st; i<=mid; i++)
w[i] = 1;
if(ask(w) != dist){
en = mid;
for(int i=st; i<=mid; i++)
w[i] = 0;
}
else
st = mid+1;
}
get_bfs_tree(U[en]);
adj[U[en]].erase(find(adj[U[en]].begin() ,adj[U[en]].end() ,make_pair(V[en] ,en)));
dist = ask(main_W);
int s = solve(U[en] ,en ,dist);
int t = solve(V[en] ,en ,dist);
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... |