#include "highway.h"
#include <bits/stdc++.h>
#define pb push_back
#define fst first
#define snd second
#define fore(i,a,b) for(ll i=a,ggdem=b;i<ggdem;++i)
#define SZ(x) ((int)x.size())
#define ALL(x) x.begin(),x.end()
#define mset(a,v) memset((a),(v),sizeof(a))
#define FIN ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define imp(v) for(auto messi:v)cout<<messi<<" "; cout<<"\n"
using namespace std;
typedef long long ll;
typedef pair<ll,ll> ii;
const ll MAXN=9e4+5;
vector<ii> g[MAXN];
ii pa[MAXN];
ll vis[MAXN],D[MAXN];
vector<int>s,h;
void dfs(ll x){
vis[x]=1;
for(auto [y,i]:g[x])if(!vis[y]){
pa[y]={x,i};
D[y]=D[x]+1;
dfs(y);
}
if(SZ(g[x])==1&&g[x][0].fst==pa[x].fst)h.pb(x);
}
ll n;
void paint(ll x, ll r=n){
fore(i,0,r){
if(pa[x].fst==-1||s[pa[x].snd]==1)break;
s[pa[x].snd]=1;
x=pa[x].fst;
}
}
/*ll ask(ll x){
s=vector<int>(m);
paint(x);
return ask(s);
}*/
void find_pair(int N, std::vector<int> U, std::vector<int> V, int A, int B) {
int M = U.size();
ll m=M,a=A,b=B;
n=N;
s.resize(m);
fore(i,0,m){
g[U[i]].pb({V[i],i});
g[V[i]].pb({U[i],i});
}
srand(175);
ll rt=rand()%n;
pa[rt]={-1,-1};
D[rt]=0;
dfs(rt);
ll d=ask(s)/a;
// cerr<<rt<<endl;
// imp(h);
ll l=0,r=SZ(h)-1;
while(l<=r){
ll mid=(l+r)/2;
s=vector<int>(m);
fore(i,0,mid+1)paint(h[i]);
if(ask(s)<d*b)l=mid+1;
else r=mid-1;
}
ll x=h[l];
l=0,r=SZ(h)-1;
while(l<=r){
ll mid=(l+r)/2;
s=vector<int>(m);
fore(i,mid,SZ(h))paint(h[i]);
if(ask(s)<d*b)r=mid-1;
else l=mid+1;
}
ll y=h[r];
/*ll flag=0;
if(ask(x)==d*b)flag=1;
else if(ask(y)==d*b)flag=1,swap(x,y);*/
l=0,r=D[x];
while(l<=r){
ll mid=(l+r)/2;
s=vector<int>(m);
paint(x,mid);
if(ask(s)==d*a)l=mid+1;
else r=mid-1;
}
ll S=x;
//cout<<r<<" r\n";
fore(i,0,r){
S=pa[S].fst;
}
/*s=vector<int>(m);
paint(x,1);
cout<<as*/
s=vector<int>(n);
for(ll y=x;y>=0;y=pa[y].fst){
s[y]=1;
}
ll lca=y;
for(ll i=y;i>=0;i=pa[i].fst){
if(s[i]){lca=i;break;}
}
ll E=-1;
if(D[lca]>=D[S]){
ll v=S;
fore(j,0,d)v=pa[v].fst;
E=v;
//cout<<"ig \n";
}
else {
for(ll i=y;i>=0;i=pa[i].fst){
if(D[i]==d-(D[S]-D[lca])+D[lca]){E=i;break;}
}
}
// cerr<<x<<" "<<y<<"\n"<<lca<<"\n";
// cout<<S<<" "<<E<<endl;
answer(S,E);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4952 KB |
Output is correct |
2 |
Correct |
1 ms |
4952 KB |
Output is correct |
3 |
Correct |
2 ms |
4952 KB |
Output is correct |
4 |
Correct |
1 ms |
5208 KB |
Output is correct |
5 |
Correct |
2 ms |
5208 KB |
Output is correct |
6 |
Correct |
1 ms |
5208 KB |
Output is correct |
7 |
Correct |
2 ms |
5208 KB |
Output is correct |
8 |
Correct |
1 ms |
4952 KB |
Output is correct |
9 |
Correct |
1 ms |
5208 KB |
Output is correct |
10 |
Correct |
1 ms |
4952 KB |
Output is correct |
11 |
Correct |
1 ms |
4952 KB |
Output is correct |
12 |
Correct |
1 ms |
5208 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
5288 KB |
Output is correct |
2 |
Correct |
10 ms |
6276 KB |
Output is correct |
3 |
Correct |
112 ms |
12796 KB |
Output is correct |
4 |
Correct |
117 ms |
13256 KB |
Output is correct |
5 |
Correct |
109 ms |
12976 KB |
Output is correct |
6 |
Correct |
131 ms |
12964 KB |
Output is correct |
7 |
Correct |
135 ms |
12520 KB |
Output is correct |
8 |
Correct |
97 ms |
12548 KB |
Output is correct |
9 |
Correct |
118 ms |
12420 KB |
Output is correct |
10 |
Correct |
93 ms |
13076 KB |
Output is correct |
11 |
Correct |
115 ms |
14396 KB |
Output is correct |
12 |
Correct |
100 ms |
14856 KB |
Output is correct |
13 |
Correct |
107 ms |
14820 KB |
Output is correct |
14 |
Correct |
143 ms |
13864 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
6696 KB |
Output is correct |
2 |
Correct |
17 ms |
7532 KB |
Output is correct |
3 |
Correct |
26 ms |
9260 KB |
Output is correct |
4 |
Correct |
62 ms |
18196 KB |
Output is correct |
5 |
Correct |
82 ms |
18288 KB |
Output is correct |
6 |
Correct |
72 ms |
18184 KB |
Output is correct |
7 |
Correct |
116 ms |
18216 KB |
Output is correct |
8 |
Correct |
63 ms |
18184 KB |
Output is correct |
9 |
Correct |
99 ms |
18184 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
5292 KB |
Output is correct |
2 |
Correct |
13 ms |
6076 KB |
Output is correct |
3 |
Correct |
77 ms |
11724 KB |
Output is correct |
4 |
Correct |
93 ms |
12524 KB |
Output is correct |
5 |
Correct |
92 ms |
12828 KB |
Output is correct |
6 |
Correct |
107 ms |
12744 KB |
Output is correct |
7 |
Correct |
107 ms |
12528 KB |
Output is correct |
8 |
Correct |
121 ms |
12988 KB |
Output is correct |
9 |
Correct |
121 ms |
12980 KB |
Output is correct |
10 |
Correct |
108 ms |
12744 KB |
Output is correct |
11 |
Correct |
100 ms |
13704 KB |
Output is correct |
12 |
Correct |
133 ms |
14656 KB |
Output is correct |
13 |
Correct |
143 ms |
14444 KB |
Output is correct |
14 |
Correct |
103 ms |
14692 KB |
Output is correct |
15 |
Correct |
116 ms |
13240 KB |
Output is correct |
16 |
Correct |
126 ms |
13156 KB |
Output is correct |
17 |
Correct |
110 ms |
14152 KB |
Output is correct |
18 |
Correct |
97 ms |
14392 KB |
Output is correct |
19 |
Correct |
95 ms |
12560 KB |
Output is correct |
20 |
Correct |
99 ms |
13904 KB |
Output is correct |
21 |
Correct |
88 ms |
12464 KB |
Output is correct |
22 |
Correct |
105 ms |
12688 KB |
Output is correct |
23 |
Correct |
120 ms |
12988 KB |
Output is correct |
24 |
Correct |
102 ms |
13888 KB |
Output is correct |
25 |
Correct |
127 ms |
17012 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
17 ms |
6432 KB |
Output is incorrect: {s, t} is wrong. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
18 ms |
6480 KB |
Output is incorrect: {s, t} is wrong. |
2 |
Halted |
0 ms |
0 KB |
- |