CodeForces - 862B (二分图染色)

Mahmoud and Ehab continue their adventures! As everybody in the evil land knows, Dr. Evil likes bipartite graphs, especially trees.

A tree is a connected acyclic graph. A bipartite graph is a graph, whose vertices can be partitioned into 2 sets in such a way, that for each edge (u, v) that belongs to the graph, u and v belong to different sets. You can find more formal definitions of a tree and a bipartite graph in the notes section below.

Dr. Evil gave Mahmoud and Ehab a tree consisting of n nodes and asked them to add edges to it in such a way, that the graph is still bipartite. Besides, after adding these edges the graph should be simple (doesn't contain loops or multiple edges). What is the maximum number of edges they can add?

A loop is an edge, which connects a node with itself. Graph doesn't contain multiple edges when for each pair of nodes there is no more than one edge between them. A cycle and a loop aren't the same .

Input

The first line of input contains an integer n — the number of nodes in the tree (1 ≤ n ≤ 105).

The next n - 1 lines contain integers u and v (1 ≤ u, v ≤ n, u ≠ v) — the description of the edges of the tree.

It's guaranteed that the given graph is a tree.

Output

Output one integer — the maximum number of edges that Mahmoud and Ehab can add to the tree while fulfilling the conditions.

Example
Input
3
1 2
1 3
Output
0
Input
5
1 2
2 3
3 4
4 5
Output
2

把所有点染成两个颜色,个数分别是s1,s2所以总连线共有s1*s2条,需要再减去已连的。其中数太大需要用vector存

#include
#include
#include
#include
#include
#include
#include
using namespace std;
int n;
int vis[100005];
vectorline[100005];
void isTwo()
{
    memset(vis,0,sizeof(vis));
    queueq;
    vis[1]=1;
    q.push(1);
    while(!q.empty())
    {
        int p=q.front();
        q.pop();
        for(int i=0;i




你可能感兴趣的:(STL,二分图)