#P6680. Graph Edge Completion

    ID: 19888 Type: Default 1000ms 256MiB

Graph Edge Completion

Graph Edge Completion

Given an undirected graph with \(N\) vertices and \(M\) edges, with no self-loops or multiple edges, perform the following operation:

If \(a < b < c\) and vertex \(a\) is connected to both vertices \(b\) and \(c\), then an edge between \(b\) and \(c\) is added.

Note that the operation is applied based solely on the original edges. Compute the final number of edges in the graph after adding all such edges.

Hint: For each vertex \(a\), consider all its neighbors \(v\) such that \(v > a\). If there are \(k\) such neighbors, the number of added edges due to vertex \(a\) is \( \binom{k}{2} = \frac{k(k-1)}{2}\).

inputFormat

The first line contains two integers (N) and (M). Each of the next (M) lines contains two integers (u) and (v) indicating that there is an edge between vertices (u) and (v). The vertices are numbered from 1 to (N).

outputFormat

Output a single integer, the final number of edges in the graph.

sample

3 2
1 2
1 3
3