func_code_string: #include <bits/stdc++.h>   int u[400000];   int v[400000];   int s[400000];   int n;   int parent[200000];   int f[200000];   int t[200001];   bool b[200000];   int tt[200000];   bool func(int x, int y) { return u[x] < u[y]; }   int main() {     scanf( %d , &n);     for (int i = 0; i < n - 1; i++) {       scanf( %d%d , &u[i], &v[i]);       u[i]--;       v[i]--;       u[n + i - 1] = v[i];       v[n + i - 1] = u[i];       t[i] = -1;     }     for (int i = 0; i < 2 * n - 2; i++) {       s[i] = i;     }     t[n - 1] = -1;     std::sort(s, s + 2 * n - 2, func);     for (int i = 0; i < 2 * n - 2; i++) {       if (t[u[s[i]]] == -1) t[u[s[i]]] = i;     }     t[n] = 2 * n - 2;     f[0] = 0;     b[0] = true;     int tail = 0;     for (int i = 0; i < n; i++) {       for (int j = t[f[i]]; j < t[f[i] + 1]; j++) {         if (b[v[s[j]]]) {           continue;         }         tail++;         f[tail] = v[s[j]];         b[f[tail]] = true;         parent[f[tail]] = f[i];       }     }     long long cnt = 0;     for (int i = n - 1; i > 0; i--) {       tt[parent[f[i]]] += tt[f[i]] + 1;       cnt = cnt + (long long)(tt[f[i]] + 1) * (n - tt[f[i]] - 1);     }     for (int i = 0; i < n; i++) b[i] = false;     int pa, pb;     pa = 0;     pb = 1;     for (int i = 1; i < n; i++) {       b[f[i]] = !b[parent[f[i]]];       if (b[f[i]])         pa++;       else         pb++;     }     cnt = cnt + (long long)pa * pb;     cnt = cnt / 2;     printf( %I64d , cnt);     return 0;   }   