#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({depth[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 |
Correct |
1 ms |
3672 KB |
Output is correct |
2 |
Correct |
1 ms |
3672 KB |
Output is correct |
3 |
Correct |
2 ms |
3760 KB |
Output is correct |
4 |
Correct |
1 ms |
3668 KB |
Output is correct |
5 |
Correct |
1 ms |
3672 KB |
Output is correct |
6 |
Correct |
1 ms |
3672 KB |
Output is correct |
7 |
Correct |
1 ms |
3792 KB |
Output is correct |
8 |
Correct |
1 ms |
3672 KB |
Output is correct |
9 |
Correct |
1 ms |
3672 KB |
Output is correct |
10 |
Correct |
1 ms |
3760 KB |
Output is correct |
11 |
Correct |
1 ms |
3672 KB |
Output is correct |
12 |
Correct |
1 ms |
3672 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
3860 KB |
Output is correct |
2 |
Correct |
14 ms |
4724 KB |
Output is correct |
3 |
Correct |
88 ms |
11160 KB |
Output is correct |
4 |
Correct |
135 ms |
11116 KB |
Output is correct |
5 |
Correct |
93 ms |
11372 KB |
Output is correct |
6 |
Correct |
125 ms |
11328 KB |
Output is correct |
7 |
Correct |
84 ms |
11440 KB |
Output is correct |
8 |
Correct |
124 ms |
11448 KB |
Output is correct |
9 |
Correct |
93 ms |
11436 KB |
Output is correct |
10 |
Correct |
120 ms |
11120 KB |
Output is correct |
11 |
Correct |
104 ms |
12308 KB |
Output is correct |
12 |
Correct |
118 ms |
12844 KB |
Output is correct |
13 |
Correct |
114 ms |
12556 KB |
Output is correct |
14 |
Correct |
91 ms |
11600 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
5248 KB |
Output is correct |
2 |
Correct |
24 ms |
6664 KB |
Output is correct |
3 |
Correct |
37 ms |
7964 KB |
Output is correct |
4 |
Correct |
104 ms |
16208 KB |
Output is correct |
5 |
Correct |
113 ms |
16340 KB |
Output is correct |
6 |
Correct |
79 ms |
16272 KB |
Output is correct |
7 |
Correct |
114 ms |
16196 KB |
Output is correct |
8 |
Correct |
86 ms |
16368 KB |
Output is correct |
9 |
Correct |
67 ms |
16368 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
3860 KB |
Output is correct |
2 |
Correct |
11 ms |
4724 KB |
Output is correct |
3 |
Correct |
71 ms |
10000 KB |
Output is correct |
4 |
Correct |
116 ms |
11112 KB |
Output is correct |
5 |
Correct |
87 ms |
11164 KB |
Output is correct |
6 |
Correct |
135 ms |
11224 KB |
Output is correct |
7 |
Correct |
90 ms |
11436 KB |
Output is correct |
8 |
Correct |
94 ms |
11452 KB |
Output is correct |
9 |
Correct |
101 ms |
11116 KB |
Output is correct |
10 |
Correct |
90 ms |
11204 KB |
Output is correct |
11 |
Correct |
96 ms |
11764 KB |
Output is correct |
12 |
Correct |
127 ms |
12612 KB |
Output is correct |
13 |
Correct |
128 ms |
12444 KB |
Output is correct |
14 |
Correct |
96 ms |
12652 KB |
Output is correct |
15 |
Correct |
91 ms |
11692 KB |
Output is correct |
16 |
Correct |
121 ms |
11336 KB |
Output is correct |
17 |
Correct |
142 ms |
12572 KB |
Output is correct |
18 |
Correct |
95 ms |
12268 KB |
Output is correct |
19 |
Correct |
106 ms |
11228 KB |
Output is correct |
20 |
Correct |
88 ms |
13120 KB |
Output is correct |
21 |
Runtime error |
98 ms |
22172 KB |
Execution killed with signal 6 |
22 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
220 ms |
262144 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
213 ms |
262144 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |