#include #include #include #include #include #include #include using namespace std; typedef long long ll; ll N; int par[1000001]; vector G[1000000]; bool used[1000000]; ll ans; void dfs(int v,ll d){ used[v] = true; ans += (d*(d+1))/2; for(int to : G[v]){ if(!used[to]) dfs(to, d+1); } } int main(){ ios::sync_with_stdio(false); cin.tie(0); cout << setprecision(10) << fixed; cin >> N; for(int i = 0; i < N-1; i++){ int a, b; cin >> a >> b; par[b] = a; a--; b--; G[a].push_back(b); G[b].push_back(a); } int r; for(int i = 1; i <= N; i++){ if(par[i] == 0){ r = i-1; break; } } dfs(r, 0); cout << ans << endl; }