// 节点编号从1开始
const lint maxn = 200000 + 10;
const lint maxm = 500000;
lint ver[maxm],ne[maxm],he[maxn],tot;
vector<lint> vex,vey;
void init(){
memset( he,0,sizeof( he ) );
tot = 1;
}
void add( lint x,lint y ){
ver[++tot] = y;
ne[tot] = he[x];
he[x] = tot;
}
struct lca{
lint de[maxn],anc[maxn][21];
queue<lint> que;
void init(){
memset( anc,-1,sizeof( anc ) );
while( que.size() ) que.pop();
}
void bfs( ){
que.push( 1 );
de[1] = 0;
while( que.size() ){
lint x = que.front();
que.pop();
for( lint cure = he[x];cure;cure = ne[cure] ){
lint y = ver[cure];
if( y == anc[x][0] ) continue;
que.push(y);
de[y] = de[x] + 1;
anc[y][0] = x;
for( lint i = 1; (1 << i) <= de[y]; i++ ){
anc[y][i] = anc[ anc[y][i-1] ][i-1];
}
}
}
}
lint solve( lint x,lint y ){
if( x == y ) return x;
if( de[x] < de[y] ) swap( x,y );
for( lint i = 18; i >= 0;i-- ){
lint an = anc[x][i];
if( an == -1 ) continue;
if( de[an] >= de[y] ){
x = an;
}
}
if( x == y ) return y;
for( lint i = 18; i >= 0; i-- ){
if( anc[x][i] == -1 || anc[y][i] ==-1 ) continue;
if( anc[x][i] != anc[y][i] ){
x = anc[x][i];
y = anc[y][i];
}
}
return anc[x][0];
}
}g;