#include #include #include struct d{ int i,dep; }; using namespace std; int main(){ int n;cin>>n; vector A(n,-1); vector C[n]; for(int i = 0; n-1 > i; i++){ int a,b;cin>>a>>b; A[--b] = --a; C[a].push_back(b); } int f = -1; for(int i = 0; n > i; i++){ if(A[i] == -1)f = i; } queue B; B.push({f,0}); A[f] = 0; while(B.size()){ auto x = B.front();B.pop(); for(int i = 0; C[x.i].size() > i; i++){ A[C[x.i][i]] = x.dep+1; B.push({C[x.i][i],x.dep+1}); } } long long ans = 0; for(int i = 0; n > i; i++){ ans += A[i]*(A[i]+1)/2; } cout << ans << endl; }