Example

Input

5
1 2
1 3
1 4
1 5


Output

6
#include <bits/stdc++.h>
using namespace std;

#define N 101111

int n;
vector <int> E[N];
unsigned long long ha[N];
const unsigned long long P = 19260817, Q = 233;

void dfs(int x, int fa = -1) {
	for (auto v : E[x]) if (v != fa) {
		dfs(v, x);
		ha[x] += ha[v];
	}
	ha[x] *= P;
	ha[x] += Q;
}

map <unsigned long long, int> G;
int main() {
	scanf("%d", &n);
	for (int i = 1, u, v; i < n; i++) {
		scanf("%d%d", &u, &v);
		E[u].push_back(v);
		E[v].push_back(u);
	}
	dfs(1);
	long long ans = 0;
	for (int i = 1; i <= n; i++) {
		ans += G[ha[i]];
		G[ha[i]] += 1; 
	}
	cout << ans << endl;
}

