#include "highway.h"
#include <queue>
#include <algorithm>
using namespace std;
typedef long long llong;
int n, m;
vector<int> edge[90000];
int dist1[90000];
int dist2[90000];
void bfs(int dist[], int S) {
for (int i = 0; i < n; ++i) dist[i] = n;
queue<int> q;
dist[S] = 0;
q.push(S);
while (!q.empty()) {
int x = q.front();
q.pop();
for (int i : edge[x]) {
if (dist[i] < n) continue;
dist[i] = dist[x] + 1;
q.push(i);
}
}
}
int ch[90000];
void find_pair(int N, vector<int> U, vector<int> V, int A, int B) {
n = N;
m = U.size();
llong d;
{
vector<int> q(m, 0);
d = ask(q);
}
int L, R;
{
int s = 0, e = m - 1;
while (s < e) {
int md = (s + e) / 2;
vector<int> q(m, 0);
for (int i = 0; i <= md; ++i) q[i] = 1;
if (ask(q) != d) e = md;
else s = md + 1;
}
L = U[s];
R = V[s];
}
for (int i = 0; i < m; ++i) {
edge[U[i]].push_back(V[i]);
edge[V[i]].push_back(U[i]);
}
bfs(dist1, L); bfs(dist2, R);
vector<int> LP, RP;
for (int i = 0; i < n; ++i) {
if (dist1[i] < dist2[i]) LP.push_back(i);
if (dist1[i] > dist2[i]) RP.push_back(i);
}
sort(LP.begin(), LP.end(), [&](int i, int j) {
return dist1[i] > dist1[j];
});
sort(RP.begin(), RP.end(), [&](int i, int j) {
return dist2[i] > dist2[j];
});
{
int s = 0, e = LP.size() - 1;
while (s < e) {
int md = (s + e) / 2;
vector<int> q(m);
for (int i = 0; i < n; ++i) ch[i] = 0;
for (int i = 0; i <= md; ++i) ch[LP[i]] = 1;
for (int i = 0; i < m; ++i) q[i] = ch[U[i]] ^ ch[V[i]];
if (ask(q) != d) e = md;
else s = md + 1;
}
L = LP[s];
}
{
int s = 0, e = LP.size() - 1;
while (s < e) {
int md = (s + e) / 2;
vector<int> q(m);
for (int i = 0; i < n; ++i) ch[i] = 0;
for (int i = 0; i <= md; ++i) ch[RP[i]] = 1;
for (int i = 0; i < m; ++i) q[i] = ch[U[i]] ^ ch[V[i]];
if (ask(q) != d) e = md;
else s = md + 1;
}
R = RP[s];
}
answer(L, R);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
2512 KB |
Output is correct |
2 |
Incorrect |
4 ms |
2424 KB |
Output is incorrect: {s, t} is wrong. |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
4 ms |
2448 KB |
Output is incorrect: {s, t} is wrong. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
22 ms |
3064 KB |
Output is incorrect: {s, t} is wrong. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
8 ms |
4856 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
27 ms |
3152 KB |
Output is incorrect: {s, t} is wrong. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
30 ms |
6128 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |