import sys

sys.setrecursionlimit(10000000)

MOD = 10 ** 9 + 7

INF = 10 ** 15



def main():

    N = int(eval(input()))

    G = [[] for _ in range(N)]

    for _ in range(N - 1):

        a,b = list(map(int,input().split()))

        a -= 1

        b -= 1

        G[a].append(b)

        G[b].append(a)

    

    parents = [-1] * N

    stack = [0]

    while stack:

        v = stack.pop()

        for e in G[v]:

            if e == 0 or parents[e] >= 0:

                continue

            parents[e] = v

            stack.append(e)

    

    ans = N

    for i in range(1,N):

        if parents[i] > i:

            ans += (parents[i] - i) * (i + 1)

        else:

            ans += (i - parents[i]) * (N - i)

    print(ans)

if __name__ == '__main__':

    main()
import sys

sys.setrecursionlimit(10000000)

MOD = 10 ** 9 + 7

INF = 10 ** 15



def main():

    N = int(eval(input()))

    ans = 0

    for i in range(N):

        ans += (i + 1)*(N - i)

    for _ in range(N - 1):

        a,b = list(map(int,input().split()))

        a -= 1

        b -= 1

        if a > b:

            a,b = b,a

        ans -= (N - b) * (a + 1)

    print(ans)

if __name__ == '__main__':

    main()
import sys

sys.setrecursionlimit(10000000)
MOD = 10**9 + 7
INF = 10**15


def main():
    N = int(eval(input()))
    G = [[] for _ in range(N)]
    for _ in range(N - 1):
        a, b = list(map(int, input().split()))
        a -= 1
        b -= 1
        G[a].append(b)
        G[b].append(a)
    parents = [-1] * N
    stack = [0]
    while stack:
        v = stack.pop()
        for e in G[v]:
            if e == 0 or parents[e] >= 0:
                continue
            parents[e] = v
            stack.append(e)
    ans = N
    for i in range(1, N):
        if parents[i] > i:
            ans += (parents[i] - i) * (i + 1)
        else:
            ans += (i - parents[i]) * (N - i)
    print(ans)


if __name__ == "__main__":
    main()

import sys

sys.setrecursionlimit(10000000)
MOD = 10**9 + 7
INF = 10**15


def main():
    N = int(eval(input()))
    ans = 0
    for i in range(N):
        ans += (i + 1) * (N - i)
    for _ in range(N - 1):
        a, b = list(map(int, input().split()))
        a -= 1
        b -= 1
        if a > b:
            a, b = b, a
        ans -= (N - b) * (a + 1)
    print(ans)


if __name__ == "__main__":
    main()

-    G = [[] for _ in range(N)] +    ans = 0 +    for i in range(N): +        ans += (i + 1) * (N - i) -        G[a].append(b) -        G[b].append(a) -    parents = [-1] * N -    stack = [0] -    while stack: -        v = stack.pop() -        for e in G[v]: -            if e == 0 or parents[e] >= 0: -                continue -            parents[e] = v -            stack.append(e) -    ans = N -    for i in range(1, N): -        if parents[i] > i: -            ans += (parents[i] - i) * (i + 1) -        else: -            ans += (i - parents[i]) * (N - i) +        if a > b: +            a, b = b, a +        ans -= (N - b) * (a + 1)