Example

Input

5
1 2
1 3
1 4
1 5


Output

6
#include <cstdio>
#include <cstring>
#include <string>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <set>
#include <iostream> 
using namespace std;
struct node
{
	int x,y;
}a[200010];
int ednum[100010];
int flag[100010];
unsigned long long dis[100010];
bool cmp(const node &a,const node &b)
{
	if(a.x==b.x) return a.y<b.y;
	return a.x<b.x;
}
unsigned long long dfs(long long x)
{
	long long j;
	unsigned long long ans=0,num=0;
	for(j=ednum[x-1];j<ednum[x];j++)
	if(flag[a[j].y]==0)
	{
		flag[a[j].y]=1;
		num=num+1;
		ans=ans+dfs(a[j].y);
		flag[a[j].y]=0;
	}
	dis[x]=num+ans*100003;
	return dis[x];
} 
int main()
{
	long long i,j,n,len,x,num,ans;
	while(~scanf("%lld",&n))
	{
		memset(ednum,0,sizeof(ednum));
		for(i=0;i<n-1;i++) 
		{
			scanf("%d%d",&a[i].x,&a[i].y);
			a[i+n-1].x=a[i].y;
			a[i+n-1].y=a[i].x;
			ednum[a[i].x]++; ednum[a[i].y]++;
		}
		for(i=1;i<=n;i++) ednum[i]+=ednum[i-1];
		sort(a,a+2*n-2,cmp);
		memset(dis,0,sizeof(dis));
		memset(flag,0,sizeof(flag));
		flag[1]=1;
		dfs(1);
		sort(dis,dis+n);
		ans=0;
		for(i=1,num=1;i<n;i++)
		{
			if(dis[i]==dis[i-1]) num++;
			else
			{
				ans=ans+(num-1)*num/2;
				num=1;
			}
		}
		ans=ans+(num-1)*num/2;
/*		for(i=1;i<=n;i++)
		{
			printf("i:%lld dis:%llu\n",i,dis[i]);
		}*/
		printf("%lld\n",ans);
	}
	return 0;
} 