#include <iostream>
#include <memory.h>
using namespace std;
const int maxn=10005;
int vis[maxn],p[maxn];
int main()
{
int T,n,i,x,y;
cin>>T;
while(T--)
{
cin>>n;
memset(vis,0,sizeof(vis));
memset(p,0,sizeof(p));
for(i=1;i<n;i++)
{
cin>>x>>y;
p[y]=x;
}
cin>>x>>y;
while(x){
vis[x]=1;
x=p[x];
}
while(y){
if(vis[y]) break;
y=p[y];
}
cout<<y<<endl;
}
return 0;
}
poj 1330
最新推荐文章于 2022-11-18 19:07:06 发布