#include "highway.h"
#include <bits/stdc++.h>
#define ll long long
#define ii pair<int,int>
#define fi first
#define se second
#define pb push_back
using namespace std;
vector<vector<ii> > vec;
vector<int> query;
vector<ii> target;
ll dist,a,b;
void dfs(int node,int high,int p){
if(high!=-1)target.pb(ii(high,node));
for(auto child:vec[node])
if(child.fi!=p)
dfs(child.fi,child.se,node);
}
void find_pair(int N, vector<int> U, vector<int> V, int A, int B) {
int M = U.size();
a=A,b=B;
vec.resize(N);
query.resize(M);
for (int i = 0; i < M; ++i)
{
vec[U[i]].pb(ii(V[i],i));
vec[V[i]].pb(ii(U[i],i));
}
int start=0;
for (int i = 0; i < N; ++i)
{
if(vec[i].size()==1){
start=i;
break;
}
}
fill(query.begin(),query.end(),0);
dist=ask(query);
dfs(start,-1,0);
//sort(target.begin(),target.end());
int l=0,r=(int)(target.size())-1;
int n1=-1,n2=-1,L=0;
while(l<r){
int med=(l+r)>>1;
L=med;
fill(query.begin(),query.end(),0);
for (int i = l; i <= med; ++i)
query[target[i].fi]=1;
ll check=ask(query);
if(check==dist)
l=med+1;
else if(check==(dist/A)*B){
r=med;
}
else{
ll nb_edges=(check-dist)/(B-A);
//cerr<<l<<" "<<r<<" "<<nb_edges<<" "<<med<<"\n";
n1=(((med-nb_edges)<0)?start:target[med-nb_edges].se);
n2=target[med+(dist-nb_edges*A)/A].se;
//cerr<<n1<<" "<<n2<<"\n";
break;
}
}
if(n1!=-1)
answer(n1, n2);
else
answer((L?target[L-1].se:start),target[L].se);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
328 KB |
Output is incorrect: {s, t} is wrong. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
376 KB |
Output is incorrect: {s, t} is wrong. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
24 ms |
1820 KB |
Output is correct |
2 |
Correct |
36 ms |
3252 KB |
Output is correct |
3 |
Correct |
56 ms |
4896 KB |
Output is correct |
4 |
Correct |
159 ms |
13408 KB |
Output is correct |
5 |
Correct |
151 ms |
13444 KB |
Output is correct |
6 |
Correct |
164 ms |
13424 KB |
Output is correct |
7 |
Correct |
147 ms |
13504 KB |
Output is correct |
8 |
Correct |
153 ms |
13432 KB |
Output is correct |
9 |
Correct |
156 ms |
13556 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
480 KB |
Output is incorrect: {s, t} is wrong. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
379 ms |
262144 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 |
364 ms |
262148 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |