#include #include using namespace std; using ll = long long; int main () { int N; cin >> N; vector> graph(N); for (int i = 0; i < N-1; i++) { int u, v; cin >> u >> v; u--, v--; graph[u].push_back(v); graph[v].push_back(u); } // 近隣を見ることで出来そう vector> count(N, vector(4)); for (int i = 0; i < N; i++) { count[i][0] = 1; count[i][1] = (int) graph[i].size(); } for (int j = 2; j <= 3; j++) { for (int i = 0; i < N; i++) { for (auto& to : graph[i]) { if (j == 2) count[i][j] += count[to][j-1] - count[i][j-2]; else count[i][j] += count[to][j-1] - count[i][j-2] + count[to][j-3]; } } } ll ans = 0; for (int i = 0; i < N; i++) ans += count[i][1] + count[i][2] + count[i][3]; ans /= 2; cout << ans << "\n"; }