Example

Input

5
1 2
1 3
1 4
1 5


Output

6
#include <bits/stdc++.h>

using namespace std;

const int N = 1e5 + 10;
const unsigned X = 1234567;
const unsigned R = 7531;

int n;
unsigned h[N];
vector <int> g[N];
map <unsigned, int> f;

void dfs (int u, int p) {
	unsigned now = 0;
	for (int v : g[u]) if (v != p) {
		dfs(v, u); 
		now += h[v];
	}
	h[u] = now * X + R;
	++f[h[u]];  
}

int main (int argc, char const *argv[]) {
	scanf("%d", &n);
	for (int i = 1; i < n; ++i) {
		int u, v;
		scanf("%d %d", &u, &v);
		g[u].push_back(v);
		g[v].push_back(u);
	}

	dfs(1, 0);

	long long ans = 0;
	for (auto it : f) {
		long long cnt = (long long) it.second;
		ans += (cnt * (cnt - 1LL))/2LL;
	}

	printf("%lld\n", ans);
	return 0;
}