import sys from collections import deque 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=[-1 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]==-1: stx=i break st[stx]=0 d={} d[0]=1 q=deque([stx]) while q: now=q.popleft() for j in tonari[now]: if st[j]==-2: st[j]=st[now]+1 if st[now]+1 not in d: d[st[now]+1]=0 d[st[now]+1]+=1 q.append(j) ans=0 st.sort(reverse=True) s=sum(st) rest=n-1 for j in st: if d[j]!=0: ans+=s s-=rest rest-=d[j] d[j]=0 print(ans)