This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "highway.h"
#include <bits/stdc++.h>
using namespace std;
#define dbgv(v) cout<<#v<<" = "; f(i,0,v.size()) cout<<v[i]<<" "; cout<<endl
#define dbga(a,x,y) cout<<#a<<" = "; f(i,x,y) cout<<a[i]<<" "; cout<<endl
#define erorp(x) cout<<#x<<"={"<<x.F<<" , "<<x.S<<"}"<<endl
#define eror(x) cout<<#x<<'='<<(x)<<endl
#define f_(i,a,b) for(int i=a;i>=b;i--)
#define f(i,a,b) for(int i=a;i<b;i++)
#define nb(x) __builtin_popcount(x)
#define all(v) v.begin(),v.end()
#define bit(n,k) (((n)>>(k))&1)
#define Add(x,y) x=(x+y)%mod
#define maxm(a,b) a=max(a,b)
#define minm(a,b) a=min(a,b)
#define lst(x) x[x.size()-1]
#define sz(x) int(x.size())
#define mp make_pair
#define ll long long
#define pb push_back
#define S second
#define F first
const int N=2e5+99;
int n,m,A,B,S,T,par[N],f[N];
ll ST;
vector<int> w,vec;
vector<pair<int,int>> g[N];
void reset(int x){
fill(w.begin(),w.end(),x);
}
void dfs(int u){
for(auto [v,id] : g[u]){
if(v==par[u]) continue ;
f[v]=id;
par[v]=u;
dfs(v);
}
vec.pb(u);
}
int find(int rt){
fill(par,par+N,-1);
vec.clear();
dfs(rt);
int l=0,r=n;
while(l+1<r){
int mid=(l+r)>>1;
reset(1);
f(i,0,mid) w[f[vec[i]]]=0;
ll res=ask(w);
if(res<ST*B){
r=mid;
}
else{
l=mid;
}
}
f(i,1,n+1) reverse(all(g[i]));
return vec[l];
}
void find_pair(int _n,vector<int> U,vector<int> V,int _A,int _B){
n=_n,m=U.size(),A=_A,B=_B;
f(i,0,m){
g[U[i]].pb({V[i],i});
g[V[i]].pb({U[i],i});
}
w.resize(m);
ST=ask(w)/A;
S=find(0);
T=find(S);
if(S==T){
while(ST--){
T=par[T];
}
}
answer(S,T);
}
/*
3 2 1 2 0 2
0 1
1 2
*/
Compilation message (stderr)
highway.cpp: In function 'void dfs(int)':
highway.cpp:35:12: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
35 | for(auto [v,id] : g[u]){
| ^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |