#include #include using namespace std; forward_list to[100000]; int main() { int N; cin >> N; for (int i = 0; i < N - 1; i++) { int a, b; cin >> a >> b; a--, b--; to[a].push_front(b); to[b].push_front(a); } long long ret = 1LL * N * N; auto f = [&N](long long x) -> long long { return x * (N - x); }; auto dfs = [&](auto self, int now, int prv) -> int { int subtree_size = 1; for (auto nxt : to[now]) { if (nxt != prv) { int tmp = self(self, nxt, now); ret += f(tmp); subtree_size += tmp; } } ret += f(subtree_size); return subtree_size; }; dfs(dfs, 0, -1); cout << ret << '\n'; }