#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define INF (long long)(2e15)
#define mod2 998244353
#define mod 1000000007
#define eps 1e-9
#define abs(x) ((x)>=0?(x):-(x))
#define y1 solai
#define fi first
#define se second
typedef int ll;
typedef long double ld;
typedef pair<ll,ll> pll;
typedef pair<double,double> pdd;
typedef pair<pll, ll> plll;
mt19937 rng(29);
const ll N=500100;
ll n,x,y,ans,cnt=1,d[N],c[N];
vector<ll>v[N];
void dfs(ll x, ll pr=0)
{
d[x]=1;
c[x]=1;
for(ll to:v[x])
{
if(to==pr)
continue;
dfs(to,x);
if(d[to]+1>d[x])
{
d[x]=d[to]+1;
c[x]=c[to];
}
else if(d[to]+1==d[x])
c[x]+=c[to];
}
}
bool cmp(ll a, ll b)
{
return d[a]>d[b];
}
void solve(ll x)
{
dfs(x);
sort(v[x].begin(),v[x].end(),&cmp);
for(ll j=0;j<v[x].size();j++)
for(ll k=j+1;k<v[x].size();k++)
for(ll i=0;i<v[x].size();i++)
{
if(i==j||i==k)
continue;
ll a=v[x][i],b=v[x][j],cc=v[x][k];
if(d[a]*(d[b]+d[cc])==ans)
{
cnt+=c[b]*c[cc];
break;
}
else if(d[a]*(d[b]+d[cc])>ans)
{
ans=d[a]*(d[b]+d[cc]);
cnt=c[b]*c[cc];
break;
}
}
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cin>>n;
for(ll i=1;i<n;i++)
cin>>x>>y,v[x].pb(y),v[y].pb(x);
for(ll i=1;i<=n;i++)
if(v[i].size()>2)
solve(i);
cout<<ans<<" "<<cnt<<endl;
}
/*
7
1 2
1 3
2 4
2 5
3 6
3 7
4
1 2
2 3
2 4
5
1 2
2 3
3 4
4 5
*/
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |