#5111. Problem 2. Making Friends
Problem 2. Making Friends
Problem 2. Making Friends
USACO 2022 December Contest, Platinum
Note: the time limit for this problem is 3s, 50% larger than the default. The memory limit is twice the default.
There are initially () pairs of friends among FJ's () cows labeled . The cows are leaving the farm for vacation one by one. On day , the -th cow leaves the farm, and all pairs of the -th cow's friends still present on the farm become friends. How many new friendships are formed in total?
INPUT FORMAT (input arrives from the terminal / stdin):
The first line contains and .
The next lines contain two integers and denoting that cows and are friends (, ). No unordered pair of cows appears more than once.
OUTPUT FORMAT (print output to the terminal / stdout):
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 , three new friendships are formed: , , and .
On day , two new friendships are formed: and .
SCORING: Test cases 2-3 satisfy .Test cases 4-7 satisfy .Test cases 8-17 satisfy no additional constraints.
Problem credits: Benjamin Qi