QOJ.ac

QOJ

Time Limit: 3 s Memory Limit: 512 MB Total points: 100
[0]

# 5337. Making Friends

Statistics

Note: the time limit for this problem is 3s, 50% larger than the default. The memory limit is twice the default.

There are initially M (1M2105) pairs of friends among FJ's N (2N2105) cows labeled 1N. The cows are leaving the farm for vacation one by one. On day i, the i-th cow leaves the farm, and all pairs of the i-th cow's friends still present on the farm become friends. How many new friendships are formed in total?

Input Format

The first line contains N and M.

The next M lines contain two integers ui and vi denoting that cows ui and vi are friends (1ui,viN, uivi). No unordered pair of cows appears more than once.

Output Format

One line containing the total number of new friendships formed. Do not include pairs of cows that were already friends at the beginning.

Sample Input

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

Sample Output

5

On day 1, three new friendships are formed: (3,4), (3,7), and (4,7).

On day 3, two new friendships are formed: (4,5) and (5,7).

Scoring

  • Test cases 2-3 satisfy N500.
  • Test cases 4-7 satisfy N104.
  • Test cases 8-17 satisfy no additional constraints.

Problem credits: Benjamin Qi