Language: C++

#include <bits/stdc++.h>
#include <array>
using namespace std;
using ULL = unsigned long long;
using UL = unsigned;
using LL = long long;
#define rep(i, n) for(UL i = 0; i < (n); i++)

struct Problem {

	void Solve() {
		UL N; cin >> N;
		vector<vector<UL>> E(N);
		rep(i, N - 1) {
			UL a, b; cin >> a >> b; a--; b--;
			E[a].push_back(b);
			E[b].push_back(a);
		}
		UL r = 0;
		vector<UL> D(N);
		{
			vector<UL> L(N); rep(i, N) L[i] = E[i].size() - 1;
			queue<UL> Q;  rep(i, N) if (L[i] == 0) Q.push(i);
			while (Q.size()) {
				UL p = Q.front(); Q.pop();
				r = max(r, D[p]);
				for (UL e : E[p]) {
					if (L[e] == 0) continue;
					D[e] = max(D[e], D[p] + 1);
					L[e]--;
					if (L[e] != 0) continue;
					Q.push(e);
				}
			}
		}
		UL Cs = 0; rep(i, N) if (D[i] == r) Cs++;
		queue<UL> Q;
		rep(i, N) if (D[i] == r) Q.push(i);
		while (Q.size()) {
			UL p = Q.front(); Q.pop();
			for (UL e : E[p]) {
				if (D[e] < D[p]) Q.push(e);
				if (D[e] > D[p]) D[p] = D[e] - 1;
			}
		}
		vector<UL> d(r + 1);
		rep(i, N) d[D[i]] = max(d[D[i]], E[i].size());
		ULL ans = 1;
		for (UL i = 1; i < r; i++) { ans *= (d[i] - 1); }
		if (Cs == 2) ans *= (d[r] - 1) * 2; else ans *= d[r];
		//rep(i, D.size()) cout << D[i] << " "; cout << endl;
		//rep(i, d.size()) cout << d[i] << " "; cout << endl;
		if (Cs == 1) {
			UL C = 0; rep(i, N) if (D[i] == r) C = i;
			for (UL v : E[C]) {
				queue<UL> Q; Q.push(C); Q.push(v);
				vector<UL> D2 = D;
				D2[v] = r;
				while (Q.size()) {
					UL p = Q.front(); Q.pop();
					for (UL e : E[p]) {
						if (D2[e] < D2[p]) Q.push(e);
						if (D2[e] > D2[p]) D2[p] = D2[e] - 1;
					}
				}
				vector<UL> d2(r + 1);
				rep(i, N) d2[D2[i]] = max(d2[D2[i]], E[i].size());
				ULL ansbuf = 1;
				for (UL i = 1; i < r; i++) { ansbuf *= (d2[i] - 1); }
				ansbuf *= (d2[r] - 1) * 2;
				//rep(i, D2.size()) cout << D2[i] << " "; cout << endl;
				//rep(i, d2.size()) cout << d2[i] << " "; cout << endl;
				ans = min(ans, ansbuf);
			}
		}
		cout << (r + 1) << " " << ans << endl;
	}


	Problem();
};
int main() {
	unique_ptr<Problem> p(new Problem());
	p->Solve();
	return 0;
}
Problem::Problem() {
	cout << fixed << setprecision(10);
}


Compiler output:
a.cc: In member function 'void Problem::Solve()':
a.cc:47:40: error: no matching function for call to 'max(__gnu_cxx::__alloc_traits<std::allocator<unsigned int>, unsigned int>::value_type&, std::vector<unsigned int>::size_type)'
   47 |                 rep(i, N) d[D[i]] = max(d[D[i]], E[i].size());
      |                                     ~~~^~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_algobase.h:257:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  257 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note:   template argument deduction/substitution failed:
a.cc:47:40: note:   deduced conflicting types for parameter 'const _Tp' ('unsigned int' and 'std::vector<unsigned int>::size_type' {aka 'long unsigned int'})
   47 |                 rep(i, N) d[D[i]] = max(d[D[i]], E[i].size());
      |                                     ~~~^~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  303 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note:   candidate expects 3 arguments, 2 provided
In file included from /usr/include/c++/14/algorithm:61:
/usr/include/c++/14/bits/stl_algo.h:5706:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(initializer_list<_Tp>)'
 5706 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5706:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5716:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(initializer_list<_Tp>, _Compare)'
 5716 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5716:5: note:   template argument deduction/substitution failed:
a.cc:47:40: note:   mismatched types 'std::initializer_list<_Tp>' and 'unsigned int'
   47 |                 rep(i, N) d[D[i]] = max(d[D[i]], E[i].size());
      |                                     ~~~^~~~~~~~~~~~~~~~~~~~~~
a.cc:67:58: error: no matching function for call to 'max(__gnu_cxx::__alloc_traits<std::allocator<unsigned int>, unsigned int>::value_type&, std::vector<unsigned int>::size_type)'
   67 |                                 rep(i, N) d2[D2[i]] = max(d2[D2[i]], E[i].size());
      |                                                       ~~~^~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  257 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note:   template argument deduction/substitution failed:
a.cc:67:58: note:   deduced conflicting types for parameter 'const _Tp' ('unsigned int' and 'std::vector<unsigned int>::size_type' {aka 'long unsigned int'})
   67 |                                 rep(i, N) d2[D2[i]] = max(d2[D2[i]], E[i].size());
      |                                                       ~~~^~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  303 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note:   candidate expects 3 arguments, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5706:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(initializer_list<_Tp>)'
 5706 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5706:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5716:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(initializer_list<_Tp>, _Compare)'
 5716 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5716:5: note:   template argument deduction/substitution failed:
a.cc:67:58: note:   mismatched types 'std::initializer_list<_Tp>' and 'unsigned int'
   67 |                                 rep(i, N) d2[D2[i]] = max(d2[D2[i]], E[i].size());
      |                                                       ~~~^~~~~~~~~~~~~~~~~~~~~~~~