atcoder#CODEFESTIVAL2017QUALBC. 3 Steps
3 Steps
Score : points
Problem Statement
Rng has a connected undirected graph with vertices. Currently, there are edges in the graph, and the -th edge connects Vertices and .
Rng will add new edges to the graph by repeating the following operation:
- Operation: Choose and such that Vertex can be reached by traversing exactly three edges from Vertex , and add an edge connecting Vertices and . It is not allowed to add an edge if there is already an edge connecting Vertices and .
Find the maximum possible number of edges that can be added.
Constraints
- The graph has no self-loops or multiple edges.
- The graph is connected.
Input
Input is given from Standard Input in the following format:
Output
Find the maximum possible number of edges that can be added.
6 5
1 2
2 3
3 4
4 5
5 6
4
If we add edges as shown below, four edges can be added, and no more.
5 5
1 2
2 3
3 1
5 4
5 1
5
Five edges can be added, for example, as follows:
- Add an edge connecting Vertex and Vertex .
- Add an edge connecting Vertex and Vertex .
- Add an edge connecting Vertex and Vertex .
- Add an edge connecting Vertex and Vertex .
- Add an edge connecting Vertex and Vertex .