local n = io.read("*n") local edge = {} local parent = {} local childcnt = {} local w = {} local asked = {} for i = 1, n do edge[i] = {} parent[i] = 0 childcnt[i] = 0 w[i] = 1 asked[i] = false end for i = 1, n - 1 do local p, q = io.read("*n", "*n") table.insert(edge[p], q) table.insert(edge[q], p) end local tasks = {1} asked[1] = true for i = 1, n do local src = tasks[i] for j = 1, #edge[src] do local dst = edge[src][j] if not asked[dst] then asked[dst] = true childcnt[src] = childcnt[src] + 1 table.insert(tasks, dst) parent[dst] = src end end end local ret = n * n tasks = {} for i = 1, n do if childcnt[i] == 0 then table.insert(tasks, i) end end for i = 1, n do local src = tasks[i] ret = ret + (n - w[src]) * w[src] local p = parent[src] for j = 1, #edge[src] do local dst = edge[src][j] if dst ~= p then ret = ret + w[dst] * (n - w[dst]) end end if 0 < p then childcnt[p] = childcnt[p] - 1 if childcnt[p] == 0 then table.insert(tasks, p) end w[p] = w[p] + w[src] end end ret = tostring(1LL * ret):gsub("LL", "") print(ret)