#P9850. Magic Circle Key Difference

    ID: 22995 Type: Default 1000ms 256MiB

Magic Circle Key Difference

Magic Circle Key Difference

Mona Megistus has discovered an ancient magic circle represented by a complete graph with \(n\) vertices. In this graph, exactly \(m\) edges are colored red while the remaining edges are blue. Mona obtains a key when she selects four distinct vertices such that all the six edges connecting these vertices have the same color. She gets a red key if all the edges are red, and a blue key if all the edges are blue.

The magic power of the circle is defined as the absolute difference between the number of red keys and blue keys. Your task is to compute this magic power.

Note: The graph is complete, i.e., every pair of distinct vertices has an edge.

The condition for a key from four vertices \(a, b, c, d\) is:

[ \text{Key exists if either } \bigwedge_{\substack{(i,j) \in {(a,b), (a,c), (a,d), (b,c), (b,d), (c,d)}}} edge_{i,j}\text{ is red, or all are blue.} ]

inputFormat

The first line contains two integers \(n\) and \(m\) \( (4 \le n, 0 \le m \le \frac{n(n-1)}{2})\), where \(n\) is the number of vertices and \(m\) is the number of red edges.

Then follow \(m\) lines, each containing two integers \(u\) and \(v\) \((1 \le u, v \le n, u \ne v)\) indicating that the edge connecting vertices \(u\) and \(v\) is red. The remaining edges in the complete graph are blue.

outputFormat

Output a single integer, the absolute difference between the number of red keys and blue keys that can be obtained from the graph.

sample

4 6
1 2
1 3
1 4
2 3
2 4
3 4
1