Example

Input

5
1 2
1 3
1 4
1 5


Output

6
#include <iostream>
#include <stdio.h>
#include <queue>
#include <string.h>
#include <vector>
#include <map>
#include <string>
#include <set>
#define ll long long
using namespace std;
const ll maxn = 1000050;
const ll mod = 1e12+7;
const ll p = 4903;
ll C[100050];
ll ha[maxn] = {0};
//vector<int> G[maxn];
int SG[maxn] = {0};
int fa[maxn] = {0};
map<ll,ll> T;
ll n;
int vis[maxn]={0};
void bfs(){
	int i;
	queue<int> q;
	for(i=1;i<=n;++i){
		ha[i] = 1;
		if(SG[i]==0) {
			q.push(i);vis[i] = 1;
		}
	}
	while(!q.empty()){
		int t = q.front();
		q.pop();
		if(t==1) continue;
		if(SG[t]!=0){//儿子没跟完 
			q.push(t);continue;
		}
		ha[fa[t]] = (ha[fa[t]]+ha[t]*p)%mod;
		SG[fa[t]]--;//少一个儿子 
		
		if(!vis[fa[t]]){//队列里还没有过 
			vis[fa[t]] = 1;q.push(fa[t]);
		}
	}
	for(i=1;i<=n;++i){
		if(T.find(ha[i])!=T.end()) T[ha[i]]++;
		else T[ha[i]] = 1;
	}
}
int main(){
	int i,a,b;
	cin>>n;
//	for(i=1;i<=n;++i) G[a].clear();
	for(i = 1;i < n; ++i){
		scanf("%d%d",&a,&b);
		//G[a].push_back(b);
		SG[a]++;
		fa[b] = a;
	}
	T.clear();
	bfs();
	map<ll,ll>::iterator it;
	ll ans = 0;
	for(it = T.begin();it!=T.end();++it){
	//	cout<<it->second<<endl;
		ans+=it->second*(it->second-1)/2;
	}
	printf("%lld\n",ans);
	return 0;
}
