Making Friends
시간 제한: 3000ms메모리 제한: 1024MB출처: USACO 2022 December PlatinumBOJ 26967
문제
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?
입력
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.
출력
One line containing the total number of new friendships formed. Do not include pairs of cows that were already friends at the beginning.
힌트
On day , three new friendships are formed: , , and .
On day , two new friendships are formed: and .
예제
예제 1
입력
7 6 1 3 1 4 7 1 2 3 2 4 3 5
출력
5
코드를 제출하려면 로그인하세요.