#include "highway.h"
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<int, int>
#define ff first
#define ss second
#define pb push_back
const int mxN = 1e5;
vector<pii> adj[mxN];
int par[mxN];
int paredge[mxN];
int depth[mxN];
void dfs1(int u = 0, int dep = 0, int pp = -1) {
depth[u] = dep;
for (pii v : adj[u]) {
if (v.ff == pp) continue;
paredge[v.ff] = v.ss;
par[v.ff] = u;
dfs1(v.ff, dep + 1, u);
}
}
void find_pair(int n, vector<int> U, vector<int> V, int A, int B) {
int m = U.size();
vector<pair<pii, int>> edges(m);
for (int i = 0; i < m; i++) {
edges[i] = {{U[i], V[i]}, i};
adj[U[i]].pb({V[i], i});
adj[V[i]].pb({U[i], i});
}
vector<int> pass(m, 0);
ll base = ask(pass);
dfs1(); paredge[0] = -1;
int S, T, LCA, ldep;
// search for last element
{
vector<pii> v;
for (int i = 1; i < n; i++) {
v.pb({paredge[i], i});
}
sort(v.begin(), v.end(), greater<pii>());
int lb = 0, rb = (int)(v.size()) - 1;
while (lb < rb) {
int mid = (lb + rb + 1) >> 1;
for (int i = 0; i < mid; i++) pass[paredge[v[i].ss]] = 1;
ll ret = ask(pass);
if (ret == base) lb = mid;
else rb = mid - 1;
for (int i = 0; i < mid; i++) pass[paredge[v[i].ss]] = 0;
}
S = v[lb].ss;
}
// search for depth of LCA
{
int lb = 0, rb = n;
while (lb < rb) {
int mid = (lb + rb + 1) >> 1;
for (int i = 1; i < n; i++) {
pass[paredge[i]] = (depth[i] <= mid);
}
ll ret = ask(pass);
if (ret == base) lb = mid;
else rb = mid - 1;
for (int i = 0; i < n; i++) pass[i] = 0;
}
ldep = lb;
}
LCA = S;
for (int i = depth[S]; i > ldep; i--) LCA = par[LCA];
if (1LL * (depth[S] - ldep) * A == base) return answer(LCA, S);
int rdep = (base / A) - (depth[S] - ldep) + ldep;
int avoid = S;
for (int i = depth[S]; i > rdep; i--) avoid = par[avoid];
// search for remaining node
{
vector<int> v;
for (int i = 0; i < n; i++) {
if (depth[i] == rdep && i != avoid) v.pb(i);
}
int lb = 0, rb = (int)(v.size()) - 1;
while (lb < rb) {
int mid = (lb + rb) >> 1;
for (int i = 0; i <= mid; i++) pass[paredge[v[i]]] = 1;
ll ret = ask(pass);
if (ret != base) rb = mid;
else lb = mid + 1;
for (int i = 0; i <= mid; i++) pass[paredge[v[i]]] = 0;
}
T = v[lb];
}
answer(S, T);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
3672 KB |
Output is incorrect: {s, t} is wrong. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
3852 KB |
Output is incorrect: {s, t} is wrong. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
5252 KB |
Output is correct |
2 |
Correct |
18 ms |
6664 KB |
Output is correct |
3 |
Correct |
24 ms |
8156 KB |
Output is correct |
4 |
Correct |
84 ms |
16188 KB |
Output is correct |
5 |
Correct |
77 ms |
16300 KB |
Output is correct |
6 |
Correct |
66 ms |
16316 KB |
Output is correct |
7 |
Correct |
115 ms |
16524 KB |
Output is correct |
8 |
Correct |
73 ms |
16300 KB |
Output is correct |
9 |
Correct |
123 ms |
16308 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
3860 KB |
Output is incorrect: {s, t} is wrong. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
214 ms |
262144 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
200 ms |
262144 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |