Example

Input

5
1 2
1 3
1 4
1 5


Output

6
#include <bits/stdc++.h>
#define N 100010
using namespace std;
typedef unsigned long long ull;
ull const Base = 1777771;
int n,par[N],in[N];

ull bfs(){
  queue<int> Q;
  ull ans=0;
  map<ull,int> M[N];
  vector<ull> H(n,1),dep(n,0);
  for(int i=0;i<n;i++)if(!in[i])Q.push(i),ans+=M[0][1]++;
  
  while(!Q.empty()){
    int pos = Q.front();Q.pop();
    int nx = par[pos];
    ull &A = H[pos],&B = H[nx];
    dep[nx] = max(dep[nx],dep[pos]+1);
    B+=A*Base;
    if(--in[nx]==0)ans+=M[dep[nx]][B]++,Q.push(nx);
  }
  return ans;
}

int main(){
  cin>>n;
  for(int i=0,a,b;i<n-1;i++){
    cin>>a>>b;
    in[a-1]++,par[b-1] = a-1;
  }
  cout<<bfs()<<endl;
  return 0;
}