WA#1#9#10求助
查看原帖
WA#1#9#10求助
1046995
hjbaoyx楼主2024/8/22 16:23
#include<bits/stdc++.h>
using namespace std;
int depth[110],j[110],pre[110];
int main() {
	int n,u,v,x,y,deep=0,maxlong=0,sum,sum1;
	scanf("%d",&n);
	depth[1]=1;
	for(int i=1;i<=n-1;++i) {
		scanf("%d%d",&u,&v);
		depth[v]=depth[u]+1;
		pre[v]=u;
	}
	scanf("%d%d",&x,&y);
	for(int i=1;i<=n;++i) deep=max(deep,depth[i]),++j[depth[i]];
	for(int i=1;i<=deep;++i) maxlong=max(maxlong,j[i]);
	sum=sum1=0;
	while(pre[x]!=0) x=pre[x],++sum;
	while(pre[y]!=0) y=pre[y],++sum1;
	printf("%d\n%d\n%d",deep,maxlong,sum*2+sum1);
	return 0;
}
2024/8/22 16:23
加载中...