bzoj1787 紧急集合

Input

Output

#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<cctype>
#include<cmath>
#include<cstdlib>
#include<queue>
#include<ctime>
#include<vector>
#include<set>
#include<map>
#include<stack>
using namespace std;
#define ri register int
const int LOG=18;
int pr[600000][LOG+3],dep[600000],cnt;
int x=0,f=1;char s=getchar();
while(s<'0'||s>'9'){if(s=='-')f=-1;s=getchar();}
while(s>='0'&&s<='9'){x=(x<<3)+(x<<1)+(s-'0');s=getchar();}
return x*f;
}
to[++cnt]=y;
to[++cnt]=x;
}
inline void dfs(int x,int fa){
pr[x][0]=fa;
if(to[i]!=fa){
dep[to[i]]=dep[x]+1;
dfs(to[i],x);
}
}
inline int lca(int x,int y){
if(dep[y]>dep[x])swap(x,y);
int ans=0;
for(ri i=LOG;i>=0;--i)
if(dep[x]-(1<<i)>=dep[y])
x=pr[x][i];
if(x==y)return x;
for(ri i=LOG;i>=0;--i)
if(pr[x][i]!=pr[y][i]){
x=pr[x][i];
y=pr[y][i];
}
return pr[x][0];
}
int main()
{     int n,m,x,y,z;
for(ri i=1;i<n;++i){
}
dep[1]=1;
dfs(1,0);
for(ri j=1;j<=LOG;++j)
for(ri i=1;i<=n;++i)
pr[i][j]=pr[pr[i][j-1]][j-1];
for(ri i=1;i<=m;++i){
}