#include <stdio.h>
//谁离根节点进谁就胜
int father[100002];
int find(int x)
{
int sum=0;
while(x!=father[x])
{
x=father[x];
sum++;
}
return sum;
}
int main()
{
int n,m,i,x,y;
while(scanf("%d %d",&n,&m)&&n)
{
for(i=1;i<=n;i++)
father[i]=i;
for(i=1;i<n;i++)
{
scanf("%d %d",&x,&y);
father[y]=x;
}
while(m--)
{
scanf("%d %d",&x,&y);
if(find(x)<=find(y))
printf("lxh\n");
else
printf("pfz\n");
}
}
return 0;
}hdu2545 树上战争
最新推荐文章于 2018-06-11 18:26:28 发布
此博客介绍了使用C++解决的竞赛问题,涉及寻找树中节点到根节点的距离,并通过比较距离来决定胜负。适用于对算法和数据结构感兴趣的编程爱好者。
628

被折叠的 条评论
为什么被折叠?



