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 pair<int,int> P;
const double EPS = 1e-12;
const int INF = numeric_limits<int>::max()/2;
const int MOD = 1e9+7;

typedef vector<vector<int>> Graph;
vector<ll> hashv(111111,0);

ll dfs(const Graph &tree, int node){
    int sz=tree[node].size();
    if(sz==0){
        return hashv[node] = 1;
        
    }

    ll tmp=0;
    for(int i=0;i<sz;i++){
        int next=tree[node][i];
        tmp += dfs(tree,next);
    }
    tmp *= MOD;
    tmp += 1;
    return hashv[node] = tmp;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);

    int n;cin>>n;
    Graph tree(n);
    for(int i=0;i<n-1;i++){
        int a,b;cin>>a>>b;
        a--;b--;
        tree[a].push_back(b);
    }
    dfs(tree,0);
    map<ll,ll> mp;
    ll res=0;
    for(int i=0;i<n;i++){
        res += mp[hashv[i]];
        mp[hashv[i]]++;
    }
    cout<<res<<endl;
}
