#include #include using namespace std; using ll = long long int; using P = pair; using graph = vector>; int dfs(graph &G, vector &isvisit, int cur, int parent){ if(isvisit[cur]) return 0; isvisit[cur] = true; int ans = 1; for(auto &p: G[cur]){ if(p.first == parent){ p.second = -1; continue; }else{ p.second = dfs(G, isvisit, p.first, cur); ans += p.second; } } return ans; } int main(){ int n; cin >> n; graph G(n); for(int i = 0; i < n-1; i++){ int a, b; cin >> a >> b; a--; b--; G[a].push_back(make_pair(b, -1)); G[b].push_back(make_pair(a, -1)); } //cerr << "input end" << endl; vector isvisit(n, false); dfs(G, isvisit, 0, -1); ll ans = 0; for(int i = 0; i < n; i++){ //for(auto &p: G[i]) cerr << "(" << p.first << ", " << p.second << ") "; //cerr << endl; ans += n; int childrenSum = 0; for(auto &p: G[i]){ if(p.second != -1) childrenSum += p.second; } for(auto &p: G[i]){ int xnum = p.second; if(xnum == -1) xnum = n-childrenSum-1; ans += (ll)(n-xnum) * xnum; } } cout << ans << endl; return 0; }