#P8907. [USACO22DEC] Making Friends P

[USACO22DEC] Making Friends P

Description

Among FJ's N(2N2×105)N(2 \le N \le 2 \times 10^5) cows numbered 1N1 \cdots N, there are initially M(1M2×105)M(1 \le M \le 2 \times 10^5) pairs of friends. The cows leave the farm one by one to go on vacation. On day ii, cow ii leaves the farm, and at the same time, all of cow ii's friends that are still on the farm become friends with each other. How many new friendship relationships are created in total?

Input Format

The first line contains NN and MM.

The next MM lines each contain two integers uiu_i and viv_i, meaning cows uiu_i and viv_i are friends (1ui,viN,uivi1 \le u_i,v_i \le N, u_i \neq v_i). Each unordered pair of cows appears at most once.

Output Format

Output one line containing the total number of new friendship relationships formed. Do not count pairs of cows that were already friends initially.

7 6
1 3
1 4
7 1
2 3
2 4
3 5
5

Hint

Explanation for Sample 1

On day 11, three new friendship relationships are created: (3,4)(3,4), (3,7)(3,7), and (4,7)(4,7).

On day 33, two new friendship relationships are created: (4,5)(4,5) and (5,7)(5,7).

Test Point Properties

  • Test points 232-3 satisfy N500N \le 500.
  • Test points 474-7 satisfy N104N \le 10^4.
  • Test points 8178-17 have no additional constraints.

Translated by ChatGPT 5