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 unsigned long long ull;
typedef long double ld;

#define pb              push_back
#define PII             pair <int,int>
#define PLL             pair <ll,ll>
#define mp              make_pair
#define xx              first
#define yy              second
#define all(v)          v.begin(),v.end()

#define lt              2*n
#define rt              2*n+1
#define clft            2*n,st,mid
#define crgt            2*n+1,mid+1,ed

#define CLR(a)          memset(a,0,sizeof(a))
#define SET(a)          memset(a,-1,sizeof(a))

#define eps             1e-9
#define PI              acos(-1.0)
#define MAX             100010
#define INF             2000000000

/******************************************************************************************/

#define mod1            1000000007
#define mod2            1000000123
#define base            100001

vector <ll> ed[MAX];
ll has1[MAX],has2[MAX];
map <PLL,ll> M;

void dfs(ll u,ll p)
{
    ll i,v,h1 = 0,h2 = 0;
    for(i=0;i<ed[u].size();i++){
        v = ed[u][i];
        if(v==p) continue;
        dfs(v,u);
        h1 += has1[v];
        h2 += has2[v];
        h1 %= mod1;
        h2 %= mod2;
    }
    has1[u] = (h1*base + 1)%mod1;
    has2[u] = (h2*base + 1)%mod2;
    M[mp(h1,h2)]++;
}

int main()
{
    //ios_base::sync_with_stdio(false);
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);

    ll n,i,u,v;
    cin >> n;
    for(i=1;i<n;i++){
        cin >> u >> v;
        ed[u].pb(v);
        ed[v].pb(u);
    }
    dfs(1,0);

    ll ans = 0;
    map <PLL,ll> :: iterator it = M.begin();
    while(it!=M.end()){
        ans += (it->second*(it->second-1))/2;
        it++;
    }
    cout << ans << endl;
    return 0;
}