A4491 「ICPC World Finals 2025」快递服务

暂无评定 传统题 ICPC 上传者
时间限制12000ms
内存限制2048MiB
通过 / 提交0/0

A4491「ICPC World Finals 2025」快递服务

暂无评定 传统题 ICPC 上传者
时间限制12000ms
内存限制2048MiB
通过 / 提交0/0

Description

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 \leq u<v \leq n).

Input

The first line of input contains two integers nn and mm, where nn (2≤n≤2⋅105)\left(2 \leq n \leq 2 \cdot 10^{5}\right) is the number of cities, and mm (1≤m≤4⋅105)\left(1 \leq m \leq 4 \cdot 10^{5}\right) 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 ith i^{\text {th }} of which contains two distinct integers aia_{i} and bib_{i} (1≤ai,bi≤n)\left(1 \leq a_{i}, b_{i} \leq n\right), denoting the home and destination cities, respectively, for courier ii.

Output

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

4 4
1 2
2 3
4 3
4 2

1
2
4
6

  1. After the first courier is hired, cities 11 and 22 are connected.
  2. After the second courier is hired, cities 22 and 33 are connected. Note, however, that cities 11 and 33 are still not connected. Even though there's a courier moving between cities 11 and 22, and a courier moving between cities 22 and 33 , they never meet each other.
  3. After the third courier is hired, cities 33 and 44 are connected and cities 22 and 44 are connected. For example, one way to deliver a package from city 22 to city 44 is:
    • hand it to courier 22 in city 22 at 19:00;
    • the next day, courier 22 arrives in city 33 at 12:00, and hands the package to courier 33 who is also in city 33;
    • at 18:00, courier 3 delivers the package to city 44.
  4. After the fourth courier is hired, all six pairs of cities are connected.