Example

Input

5
1 2
1 3
1 4
1 5


Output

6
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <deque>
#include <queue>
#include <map>
#include <stack>
#include <vector>
using namespace std;


const int mod=1e9+7;
const int maxn=1e6+10;
#define mem(a,b) memset(a,b,sizeof(a))
#define uLL unsigned long long

map<uLL,uLL> mp;
vector<int> g[maxn];

uLL d[maxn];
uLL ans;
int n;

int head[maxn],cntroad;
struct Edge {
    Edge(int V = 0,int N = 0):v(V),Next(N) {}
    int v,Next;
}road[maxn<<1];
void addedge(int u,int v) {road[cntroad] = Edge(v,head[u]); head[u] = cntroad++;}
void dfs(int u,int fa)
{
    d[u]=1;
    for(int i = head[u]; i != -1; i = road[i].Next)
    {
        int v=road[i].v;
        if(v==fa)continue;
        dfs(v,u);
        d[u]+=d[v]*mod;
    }
    mp[d[u]]++;
}
int main()
{
    while(~scanf("%d",&n))
    {
        mem(head,-1);
        cntroad = 0;
        mp.clear();
        ans=0;
        for(int i=1;i<n;i++)
        {
            int u,v;
            scanf("%d%d",&u,&v);
            addedge(u,v);
            addedge(v,u);
        }

        dfs(1,0);
        for(map<uLL,uLL>::iterator it=mp.begin(); it!=mp.end(); it++)
            ans+=(uLL)it->second*(it->second-1)/2;
        cout << ans;printf("\n");
    }
    return 0;
}

