Language: C++

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))


int par[102];
int rank[102];

void init(int n)
{
        for(int i = 0; i < n; i++){
                    par[i] = i;
                            rank[i] = 0;
                                }
}

int find(int x)
{
        if(par[x] == x){
                    return x;
                        } else {
                                    return par[x] = find(par[x]);
                                        }
}

void unite(int x, int y)
{
        x = find(x);
            y = find(y);
                if(x == y){
                            return ;
                                }
                                    if(rank[x] , rank[y]){
                                                par[x] = y;
                                                    } else {
                                                                par[y] = x;
                                                                        if(rank[x] == rank[y]){
                                                                                        rank[x]++;
                                                                                                }
                                                                                                    }
}

bool same(int x, int y)
{
        return find(x) == find(y);
}
int main() {
    //cout.precision(10);
    init(102);
    int n;
    cin >> n;
    if(n == 2){
        cout << 1 << endl << 2 << endl;
    }
    int d[102][102];
    for(int i = 0; i < 102; i++){
        for(int j = 0; j < 102; j++){
            d[i][j] = INF;
        }
        d[i][i] = 0;
    }
    int a[102];
    int b[102];
    for(int i = 1; i <= n - 1; i++){
        int in1, in2;
        cin >> in1 >> in2;
        d[in1][in2] = 1;
        d[in2][in1] = 1;
        a[i] = in1;
        b[i] = in2;
    }
    for(int k = 1; k <= n; k++){
        for(int i = 1; i <= n; i++){
            for(int j = 1; j <= n; j++){
                d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
                d[j][i] = d[i][j];
            }
        }
    }
    int radius = INF;
    vector<int> center;
    for(int i = 1; i <= n; i++){
        int test = 0;
        for(int j = 1; j <= n; j++){
            test = max(test, d[i][j]);
        }
        if(radius < test){
            continue;
        }
        if(radius == test){
            center.push_back(i);
        }
        if(radius > test){
            while(!center.empty()){
                center.pop_back();
            }
            center.push_back(i);
            radius = test;
        }
    }
    cout << radius - center.size() + 2 << endl;
    long long ans1 = INF;
    if(center.size() == 1){
        for(int i = 1; i <= n - 1; i++){
            if((a[i] == center[0]) || (b[i] == center[0])){
                continue;
            }
            unite(a[i], b[i]);
        }
        int leaf[102];
        for(int i = 0; i < 102; i++){
            leaf[i] = 0;
        }
        leaf[center[0]] = INF;
        for(int i = 1; i <= n; i++){
            int check = 0;
            for(int j = 1; j <= n; j++){
                if(d[i][j] == 1){
                    check++;
                }
            }
            if(check == 1){
                leaf[par[i]]++;
            }
        }
        long long ans = 0;
        for(int i = 1; i <= n; i++){
            if(i == center[0]){
                continue;
            }
            ans = max(ans, (long long)leaf[par[i]]);
        }
        int number = 0;
        for(int i = 1; i <= n; i++){
            if(d[i][center[0]] == 1){
                number++;
            }
        }
        ans1 = number * ans;
        int maxi = 0;
        leaf[0] = -1;
        for(int i = 1; i <= n; i++){
            if(d[i][center[0]] != 1){
                continue;
            }
            if(leaf[par[i]] > leaf[par[maxi]]){
                maxi = i;
            }
        }
        //cout << "maxi " << maxi << endl;
        center.push_back(maxi);
    }
    init(102);
    if(center.size() == 2){
        for(int i = 1; i <= n - 1; i++){
            if((a[i] == center[0]) || (b[i] == center[0])){
                continue;
            }
            if((a[i] == center[1]) || (b[i] == center[1])){
                continue;
            }
            unite(a[i], b[i]);
        }
        int leaf[102];
        for(int i = 0; i < 102; i++){
            leaf[i] = 0;
        }
        leaf[center[0]] = INF;
        for(int i = 1; i <= n; i++){
            int check = 0;
            for(int j = 1; j <= n; j++){
                if(d[i][j] == 1){
                    check++;
                }
            }
            if(check == 1){
                leaf[par[i]]++;
            }
        }
        long long ans = 0;
        for(int i = 1; i <= n; i++){
            if(i == center[0]){
                continue;
            }
            if(i == center[1]){
                continue;
            }
            ans = max(ans, (long long)leaf[par[i]]);
        }
        int number1 = 0;
        for(int i = 1; i <= n; i++){
            if(d[i][center[0]] == 1){
                number1++;
            }
        }
        int number2 = 0;
        for(int i = 1; i <= n; i++){
            if(d[i][center[1]] == 1){
                number2++;
            }
        }
        cout << min(ans1, (long long)(max(number1, number2) - 1) * 2 * ans) << endl;
        return 0;
    }

    return 0;
}

Compiler output:
a.cc: In function 'void init(int)':
a.cc:31:29: error: reference to 'rank' is ambiguous
   31 |                             rank[i] = 0;
      |                             ^~~~
In file included from /usr/include/c++/14/bits/move.h:37,
                 from /usr/include/c++/14/bits/exception_ptr.h:41,
                 from /usr/include/c++/14/exception:166,
                 from /usr/include/c++/14/ios:41,
                 from /usr/include/c++/14/ostream:40,
                 from /usr/include/c++/14/iostream:41,
                 from a.cc:1:
/usr/include/c++/14/type_traits:1437:12: note: candidates are: 'template<class> struct std::rank'
 1437 |     struct rank
      |            ^~~~
a.cc:25:5: note:                 'int rank [102]'
   25 | int rank[102];
      |     ^~~~
a.cc: In function 'void unite(int, int)':
a.cc:51:40: error: reference to 'rank' is ambiguous
   51 |                                     if(rank[x] , rank[y]){
      |                                        ^~~~
/usr/include/c++/14/type_traits:1437:12: note: candidates are: 'template<class> struct std::rank'
 1437 |     struct rank
      |            ^~~~
a.cc:25:5: note:                 'int rank [102]'
   25 | int rank[102];
      |     ^~~~
a.cc:51:50: error: reference to 'rank' is ambiguous
   51 |                                     if(rank[x] , rank[y]){
      |                                                  ^~~~
/usr/include/c++/14/type_traits:1437:12: note: candidates are: 'template<class> struct std::rank'
 1437 |     struct rank
      |            ^~~~
a.cc:25:5: note:                 'int rank [102]'
   25 | int rank[102];
      |     ^~~~
a.cc:55:76: error: reference to 'rank' is ambiguous
   55 |                                                                         if(rank[x] == rank[y]){
      |                                                                            ^~~~
/usr/include/c++/14/type_traits:1437:12: note: candidates are: 'template<class> struct std::rank'
 1437 |     struct rank
      |            ^~~~
a.cc:25:5: note:                 'int rank [102]'
   25 | int rank[102];
      |     ^~~~
a.cc:55:87: error: reference to 'rank' is ambiguous
   55 |                                                                         if(rank[x] == rank[y]){
      |                                                                                       ^~~~
/usr/include/c++/14/type_traits:1437:12: note: candidates are: 'template<class> struct std::rank'
 1437 |     struct rank
      |            ^~~~
a.cc:25:5: note:                 'int rank [102]'
   25 | int rank[102];
      |     ^~~~
a.cc:56:89: error: reference to 'rank' is ambiguous
   56 |                                                                                         rank[x]++;
      |                                                                                         ^~~~
/usr/include/c++/14/type_traits:1437:12: note: candidates are: 'template<class> struct std::rank'
 1437 |     struct rank
      |            ^~~~
a.cc:25:5: note:                 'int rank [102]'
   25 | int rank[102];
      |     ^~~~