atcoder#RELAY2D. Shock
Shock
Score : points
Problem Statement
You are given an undirected graph . has vertices and edges. The vertices are numbered from through , and the -th edge connects Vertex and . does not have self-loops and multiple edges.
You can repeatedly perform the operation of adding an edge between two vertices. However, must not have self-loops or multiple edges as the result. Also, if Vertex and are connected directly or indirectly by edges, your body will be exposed to a voltage of volts. This must also be avoided.
Under these conditions, at most how many edges can you add? Note that Vertex and are never connected directly or indirectly in the beginning.
Constraints
- All pairs are distinct.
- Vertex and in are not connected directly or indirectly by edges.
Input
Input is given from Standard Input in the following format:
Output
Print the maximum number of edges that can be added.
4 1
1 3
2
As shown above, two edges can be added. It is not possible to add three or more edges.
2 0
0
No edge can be added.
9 6
1 4
1 8
2 5
3 6
4 8
5 7
12