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 st[stx]=-1 d={} d[0]=1 def dfs(now,ch): for j in tonari[now]: if st[j]!=-1: st[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) st.sort(reverse=True) s=sum(visit) rest=n-1 for j in st: if d[j]!=0: ans+=s s-=rest rest-=d[j] d[j]=0 print(ans)