아직 만들고 있는 페이지입니다.

이 페이지는 아직 만드는 중입니다. 보이는 내용은 바뀔 수 있습니다.

Making Friends

면접 대비

시간 제한3초메모리 제한1024 MB

요약
소들이 하루에 한 마리씩 떠나고, 떠날 때 남아 있는 친구들끼리 모두 친구가 된다. 새로 생기는 친구 관계의 총 개수를 센다.
난이도

보통10점 중 7점

유형
그래프, 유니온 파인드, 구현, 수학
정답자
아직 제출이 없습니다

문제

There are initially MM (1≤M≤2⋅1051\le M\le 2\cdot 10^5) pairs of friends among FJ's NN (2≤N≤2⋅1052\le N\le 2\cdot 10^5) cows labeled 1…N1\dots N. The cows are leaving the farm for vacation one by one. On day ii, the ii-th cow leaves the farm, and all pairs of the ii-th cow's friends still present on the farm become friends. How many new friendships are formed in total?

입력

The first line contains NN and MM.

The next MM lines contain two integers u_iu\_i and v_iv\_i denoting that cows u_iu\_i and v_iv\_i are friends (1≤u_i,v_i≤N1\le u\_i,v\_i\le N, u_i≠v_iu\_i\neq v\_i). 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 11, three new friendships are formed: (3,4)(3,4), (3,7)(3,7), and (4,7)(4,7).

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

예제1

  1. 예제 1

    입력
    7 6
    1 3
    1 4
    7 1
    2 3
    2 4
    3 5
    
    예상 출력
    5