80分求助,#8,#9
查看原帖
80分求助,#8,#9
163369
NewSoul_楼主2021/10/14 17:17
#include<bits/stdc++.h>
using namespace std;
int bullet[1001];
struct tree
{
    int father;
    int left;
    int right;
    int deep;
};
tree a[101];
int main()
{
    int i,j,k,n,max=1,m;
    cin>>n;
    a[1].deep=1;
    a[1].father=0;
    for(i=1;i<n;i++)
	{
        int x,y;
        cin>>x>>y;
        if(a[x].left==0) a[x].left=y;
        else a[x].right=y;
        a[y].father=x;
        a[y].deep=a[x].deep+1;
        if(a[y].deep>=max)
            max=a[y].deep;
    }
    cin>>k>>m;
    int kd=0;
    while(a[k].father!=0)
	{
        k=a[k].father;
        kd++;
    }
    kd*=2;
    int cnot=0;
    while(a[m].father!=0)
	{
        m=a[m].father;
        cnot++;
    }
    for(i=1;i<=n;i++)
        bullet[a[i].deep]++;
    sort(bullet+1,bullet+100+1);
    cout<<max<<endl<<bullet[100]<<endl<<kd+cnot;
    return 0;
}

#8,#9没过

2021/10/14 17:17
加载中...