#CF862B. Mahmoud and Ehab and the bipartiteness

Mahmoud and Ehab and the bipartiteness

Mahmoud and Ehab and the bipartiteness

  • 时间限制:2 秒
  • 内存限制:250 MiB

题目描述

给定一棵有 nn 个节点的树。你可以向树中添加边,要求最终的图仍为二分图且是简单图,即没有自环和重边。求最多能添加多少条边。

树是连通且无环的无向图。二分图的顶点可以分为两个集合,每条边的两个端点必须位于不同集合。

输入格式

第一行一个整数 nn。

接下来 n−1n-1 行,每行两个整数 u,vu,v,表示树的一条边。保证输入是一棵树。

输出格式

输出一个整数,表示最多可以添加的边数。

样例输入 1

3
1 2
1 3

样例输出 1

0

样例输入 2

5
1 2
2 3
3 4
4 5

样例输出 2

2

样例说明 2

可以添加边 (1,4)(1,4) 和 (2,5)(2,5)。

数据范围

对于所有测试数据,保证:

  • 1≤n≤1051\le n\le10^5;
  • 1≤u,v≤n1\le u,v\le n,u≠vu\ne v;
  • 输入图连通且无环。

附件

bipartite.zip