#include "highway.h"
#include <bits/stdc++.h>
#define int long long
using namespace std;
struct edge{
int id, v;
};
int N, M, A, B;
vector<vector<edge> > graph;
void dfs(int u, int par, int id, int d, int dist, vector<int>& idlist, vector<int>& vlist){
if(d == dist){
idlist.push_back(id);
vlist.push_back(u);
}
for(edge e : graph[u]) if(e.v!=par){
dfs(e.v, u, e.id, d+1, dist, idlist, vlist);
}
}
int findT(int S, int par, int dist, int id){
vector<int> idlist, vlist;
dfs(S, par, id, 0, dist, idlist, vlist);
int L = 0, R = idlist.size();
while(L!=R-1){
//cout<<"L: "<< L<< "R: "<<R;
int Mi = (L+R)/2;
vector<signed> w(M, 0);
for(int i = L; i<Mi; i++){
w[idlist[i]]=1;
}
if(ask(w)==dist*A){
L = Mi;
}
else{
R = Mi;
}
}
return vlist[L];
}
int findedge(int dist){
int L = 0, R = M;
while(L!=R-1){
int Mi = (L+R)/2;
vector<signed> w(M, 0);
for(int i = L; i<Mi; i++){
w[i]=1;
}
if(ask(w)==dist*A){
L = Mi;
}
else{
R = Mi;
}
}
return L;
}
void dfs2(int u, int par, int id, vector<signed> & w){
w[id] = 1;
for(edge e : graph[u]) if(e.v!=par){
dfs2(e.v, u, e.id, w);
}
}
void find_pair(signed _N, vector<signed> U, vector<signed> V, signed _A, signed _B) {
N = _N;
M = U.size();
A = _A;
B = _B;
graph.resize(N);
for(int i = 0; i<M; i++){
graph[U[i]].push_back({i, V[i]});
graph[V[i]].push_back({i, U[i]});
}
vector<signed> w(M, 0);
int dist = ask(w)/A;
int ed = findedge(dist);
//cout<<"edge: "<<U[ed]<<" "<<V[ed]<<endl;
dfs2(V[ed], U[ed], ed, w);
int d1 = (ask(w)-dist*A)/(B-A)-1;
int d2 = dist - d1 - 1;
//cout<<"d1: "<<d1<<" d2: "<<d2<<endl;
int S = findT(V[ed], U[ed], d1, ed);
int T = findT(U[ed], V[ed], d2, ed);
answer(S,T);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
248 KB |
Output is correct |
2 |
Incorrect |
2 ms |
324 KB |
Output is incorrect: {s, t} is wrong. |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
496 KB |
Output is incorrect: {s, t} is wrong. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
20 ms |
2140 KB |
Output is correct |
2 |
Correct |
36 ms |
3884 KB |
Output is correct |
3 |
Correct |
43 ms |
6012 KB |
Output is correct |
4 |
Correct |
169 ms |
14864 KB |
Output is correct |
5 |
Correct |
164 ms |
14904 KB |
Output is correct |
6 |
Correct |
161 ms |
16592 KB |
Output is correct |
7 |
Correct |
153 ms |
18096 KB |
Output is correct |
8 |
Correct |
162 ms |
15820 KB |
Output is correct |
9 |
Correct |
161 ms |
16020 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
412 KB |
Output is incorrect: {s, t} is wrong. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
411 ms |
262148 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
383 ms |
262148 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |