Example

Input

5
1 2
1 3
1 4
1 5


Output

6
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int>pii;
const int N = 1e5+5;
const ll p = 9901;
const ll mod = 1e9+7;
const double eps = 1e-8;
int n,m,k;
ll has[N];
vector<int>edg[N];
map<ll,ll>mp;
map<ll,ll>::iterator it;
void dfs(int u,int fa){
    has[u]=1;
    for(int v:edg[u]){
        dfs(v,u);
        has[u]=(has[u]+has[v]*p)%mod;
    }
    mp[has[u]]++;
}
int main()
{
    int u,v;
    scanf("%d",&n);
    for(int i=1;i<n;i++){
        scanf("%d%d",&u,&v);
        edg[u].push_back(v);
    }
    dfs(1,0);
    ll ans=0;
    for(it =mp.begin();it!=mp.end();it++){
        ans+=(it->second-1)*it->second/2;
    }
    printf("%lld\n",ans);
    return 0;
}