#P7157. Counting Indirect Conversion Relations

    ID: 20361 Type: Default 1000ms 256MiB

Counting Indirect Conversion Relations

Counting Indirect Conversion Relations

Given n states numbered from 1 to n, there are k direct conversion relationships between these states. Each conversion relationship is provided as an unordered pair ( (u_i, v_i) ), meaning that state ( u_i ) and state ( v_i ) are directly connected. Two states are said to have an Indirect Conversion Relationship if they are not directly connected but there exists a sequence of direct conversion relationships (i.e. a path in the graph) connecting them.

Since it is guaranteed that every state can reach every other state via direct or indirect conversions (i.e. the graph is connected), every pair of states that is not directly connected has an indirect conversion relationship. Therefore, the total number of indirect conversion relationships is given by:

[ \text{Indirect Relations} = \binom{n}{2} - k ]

Your task is to compute this number.

inputFormat

The first line contains two integers n and k. Each of the next k lines contains two integers ( u_i ) and ( v_i ), indicating that there is a direct conversion relationship between state ( u_i ) and state ( v_i ).

outputFormat

Output a single integer representing the number of indirect conversion relationships.

sample

3 2
1 2
2 3
1