显示代码纯文本
#include <bits/stdc++.h>
#define pb emplace_back
using namespace std;
typedef long long ll;
const int maxn = 2e5 + 5;
int n;
vector<int> g[maxn];
ll ans = 0;
void dfs(int u,int fa,int dep) {
ans += dep >> 1;
for(auto v : g[u]) {
if(v == fa)continue ;
dfs(v , u , dep + 1);
}
return ;
}
int main() {
freopen("Sergeyas.in","r",stdin);
freopen("Sergeyas.out","w",stdout);
scanf("%d",&n);
if(n > maxn)return 0;
for(int i = 1;i < n;++ i) {
int u,v;
scanf("%d%d",&u,&v);
g[u].pb(v);
g[v].pb(u);
}
for(int i = 1;i <= n;++ i)dfs(i , 0 , 1);
printf("%lld",ans / 2);
fclose(stdin);
fclose(stdout);
return 0;
}