// 想定 TLE (二乗オーダー) #include #include using namespace std; vector 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_back(b); to[b].push_back(a); } long long ret = 0; auto dfs = [&](auto self, int now, int prv) -> int { int subtree_size = 1; for (auto nxt : to[now]) { if (nxt != prv) subtree_size += self(self, nxt, now); } ret += subtree_size; return subtree_size; }; for (int s = 0; s < N; s++) dfs(dfs, s, -1); cout << ret << '\n'; }