import sys sys.setrecursionlimit(1000000) stdin=sys.stdin ip=lambda: int(sp()) fp=lambda: float(sp()) lp=lambda:list(map(int,stdin.readline().split())) sp=lambda:stdin.readline().rstrip() yp=lambda:print('Yes') np=lambda:print('No') n=ip() tonari=[[] for _ in range(n)] st=[0 for _ in range(n)] for _ in range(n-1): a,b=lp() tonari[a-1].append(b-1) st[b-1]+=1 for i in range(n): if st[i]==0: stx=i break visit=[-1 for _ in range(n)] visit[stx]=0 d={} d[0]=1 def dfs(now,ch): for j in tonari[now]: if visit[j]==-1: visit[j]=ch+1 if ch+1 not in d: d[ch+1]=0 d[ch+1]+=1 dfs(j,ch+1) ans=0 dfs(stx,0) visit.sort(reverse=True) s=sum(visit) rest=n-1 for j in visit: if d[j]!=0: ans+=s s-=rest rest-=d[j] d[j]=0 print(ans)