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;
typedef long long ll;
#define all(x) (x).begin(), (x).end()
const int MAXN = 1e5 + 3e2;
vector<pair<int, int>> g[MAXN];
void find_pair(int N, vector<int> U, vector<int> V, int A, int B) {
int M = U.size();
for (int i = 0; i < M; i++){
g[U[i]].emplace_back(V[i], i);
g[V[i]].emplace_back(U[i], i);
}
vector<int> w(M, 0);
ll onlyA = ask(w);
int ind = 0;
int l = 0, r = M - 1;
while (l <= r){
int mid = (l + r) >> 1;
fill(all(w), 0);
for (int i = 0; i <= mid; i++) w[i] = 1;
ll res = ask(w);
if (res != onlyA){
ind = mid;
r = mid - 1;
} else l = mid + 1;
}
int v = V[ind];
queue<int> q;
vector<bool> used(N, false);
vector<int> p(N, 0);
used[v] = true;
q.push(v);
vector<int> edges;
while (!q.empty()){
int x = q.front(); q.pop();
for (auto e : g[x]){
int y = e.first, i = e.second;
if (!used[y]){
used[y] = true;
q.push(y);
p[y] = i;
edges.push_back(i);
}
}
}
int S = -1, T = -1;
l = 0, r = edges.size() - 1;
while (l <= r){
int mid = (l + r) >> 1;
fill(all(w), 1);
for (int i = 0; i <= mid; i++) w[edges[i]] = 0;
ll res = ask(w);
if (res == onlyA){
int i = edges[mid];
if (p[U[i]] == i) S = U[i]; else
S = V[i];
r = mid - 1;
} else l = mid + 1;
}
fill(all(used), false);
fill(all(p), 0);
used[S] = true;
q.push(S);
edges.clear();
while (!q.empty()){
int x = q.front(); q.pop();
for (auto e : g[x]){
int y = e.first, i = e.second;
if (!used[y]){
used[y] = true;
q.push(y);
p[y] = i;
edges.push_back(i);
}
}
}
l = 0, r = edges.size() - 1;
while (l <= r){
int mid = (l + r) >> 1;
fill(all(w), 1);
for (int i = 0; i <= mid; i++) w[edges[i]] = 0;
ll res = ask(w);
if (res == onlyA){
int i = edges[mid];
if (p[U[i]] == i) T = U[i]; else
T = V[i];
r = mid - 1;
} else l = mid + 1;
}
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... |