Delivery Service

시간 제한12초메모리 제한2048 MB

요약
m명의 배달원을 한 명씩 고용한 뒤, 양방향으로 소포를 주고받을 수 있는 도시 쌍의 수를 구한다.
난이도

보통10점 중 7점

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

문제

The Intercity Caspian Package Company (ICPC) is starting a delivery service which will deliver packages between various cities near the Caspian Sea. The company plans to hire couriers to carry packages between these cities.

Each courier has a home city and a destination city, and all couriers have exactly the same travel schedule: They leave their home city at 9:00, arrive at their destination city at 12:00, leave their destination city at 14:00 and return to their home city at 17:00. While couriers are in their home or destination cities, they can receive packages from and/or deliver packages to customers. They can also hand off to or receive packages from other couriers who are in that city at the same time. Since ICPC is a personal service, packages are never left in warehouses or other facilities to be picked up later – unless the package has reached its destination, couriers have to either keep the package with themselves (during the day or during the night), or hand it off to another courier.

The company will direct the couriers to hand off packages in such a way that any package can always be delivered to its destination. Or so it is hoped! We’ll say that two cities uu and vv are connected if it is possible to deliver a package from city uu to city vv as well as from vv to uu. To estimate the efficiency of their hiring process, the company would like to find, after each courier is hired, the number of pairs of cities (u,v)(u, v) that are connected (1≤u<v≤n1 ≤ u < v ≤ n).

입력

The first line of input contains two integers nn and mm, where nn (2≤n≤2⋅1052 ≤ n ≤ 2 \cdot 10^5) is the number of cities, and mm (1≤m≤4⋅1051 ≤ m ≤ 4 \cdot 10^5) is the number of couriers that will be hired. Couriers are numbered 11 to mm, in the order they are hired. This is followed by mm lines, the iith of which contains two distinct integers a_ia\_i and b_i\_i (1≤a_i,b_i≤n1 ≤ a\_i , b\_i ≤ n), denoting the home and destination cities, respectively, for courier ii.

출력

Output mm integers, denoting the number of pairs of connected cities after hiring the first 1,2,…,m1, 2, \dots , m couriers.

예제1

  1. 예제 1

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