#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 p){
nodes.clear();
vector <int> vis(n ,0);
vis[s] = vis[p] = 1;
queue <pair<int,int>> nxt;
for(auto e : adj[s])
if(e.first == p)
nxt.push(e);
while(!nxt.empty()){
int u = nxt.front().first ,f = nxt.front().second; nxt.pop();
nodes.push_back({u ,f});
for(auto e : adj[u])
if(!vis[e.first])
nxt.push(e) ,vis[e.first] = 1;
}
}
int solve(int u ,int v ,long long dist){
bfs(u ,v);
int st = 0 ,en = nodes.size()-1 ,mid;
while(st < en){
mid = (st+en+1)>>1;
vector <int> w(m ,0);
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){
vector <bool> vis(n);
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;
t_adj[u].push_back(e);
nxt.push(e.first);
}
}
}
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});
long long dist = ask(vector<int>(m ,0));
int st = 0 ,en = m-1 ,mid;
while(st < en){
mid = (st+en)>>1;
vector <int> w(m ,0);
for(int i=st; i<=mid; i++)
w[i] = 1;
if(ask(w) != dist)
en = mid;
else
st = mid+1;
}
get_bfs_tree(U[en]);
for(int i=0; i<n; i++)
swap(adj[i] ,t_adj[i]);
int s = solve(U[en] ,V[en] ,dist);
int t = solve(V[en] ,U[en] ,dist);
answer(s ,t);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
7 ms |
4548 KB |
Output is incorrect: {s, t} is wrong. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
4592 KB |
Output is correct |
2 |
Correct |
27 ms |
5432 KB |
Output is correct |
3 |
Correct |
212 ms |
12892 KB |
Output is correct |
4 |
Incorrect |
192 ms |
12892 KB |
Output is incorrect: {s, t} is wrong. |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
24 ms |
5496 KB |
Output is incorrect: {s, t} is wrong. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
4644 KB |
Output is correct |
2 |
Incorrect |
17 ms |
5376 KB |
Output is incorrect: {s, t} is wrong. |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
24 ms |
5408 KB |
Output is correct |
2 |
Correct |
31 ms |
5564 KB |
Output is correct |
3 |
Correct |
230 ms |
13240 KB |
Output is correct |
4 |
Incorrect |
229 ms |
12464 KB |
Output is incorrect: {s, t} is wrong. |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
27 ms |
5456 KB |
Output is correct |
2 |
Correct |
33 ms |
5496 KB |
Output is correct |
3 |
Correct |
236 ms |
12636 KB |
Output is correct |
4 |
Incorrect |
191 ms |
13328 KB |
Output is incorrect: {s, t} is wrong. |
5 |
Halted |
0 ms |
0 KB |
- |