#include<bits/stdc++.h>
using namespace std;
int n,m,s;
int const zyq =500005;
int next[zyq*2],first[zyq*2],go[zyq*2];
int f[zyq][21];
int dep[zyq];
int x,y;
int tot;
inline int read()
{
int x=0,f=1;char ch=getchar();
while (ch<'0'||ch>'9'){if (ch=='-') f=-1;ch=getchar();}
while (ch>='0'&&ch<='9'){x=x*10+ch-48;ch=getchar();}
return x*f;
}
void add(int u,int v){
next[++tot]=first[u];first[u]=tot;go[tot]=v;
next[++tot]=first[v];first[v]=tot;go[tot]=u;
}
void dealfirst(int u,int fa){
dep[u]=dep[fa]+1;
for(int i=0;i<=19;i++) f[u][i+1]=f[f[u][i]][i];
for(int e=first[u];e;e=next[e]){
int v=go[e];
if(v==fa) continue;
f[v][0]=u;
dealfirst(v,u);
}
}
int lca(int x,int y){
if(dep[x]<dep[y]) swap(x,y);
for(int i=20;i>=0;i--){
if(dep[f[x][i]]>=dep[y]) x=f[x][i];
if(x==y) return x;
}
for(int i=20;i>=0;i--){
if(f[x][i]!=f[y][i]){
x=f[x][i];
y=f[y][i];
}
}
return f[x][0];
}
int main(){
n=read(),m=read(),s=read();
for(int i=1;i<=n-1;i++){
x=read(),y=read();
add(x,y);
}
dealfirst(s,0);
while(m--){
x=read(),y=read();
printf("%d\n",lca(x,y));
}
return 0;
}
这段代码能在C++98却不能在C++14下运行,显示对next数组的引用有歧义