#P14284. [ICPC 2025 WF] Delivery Service

[ICPC 2025 WF] Delivery Service

题目描述

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. So it is hoped! We'll say that two cities u u and v v are connected if it is possible to deliver a package from city u u to city v v as well as from v v to u u . 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 (1u<vn 1 \le u < v \le n ).

输入格式

The first line of input contains two integers n n and m m , where n n (2n2105 2 \le n \le 2 \cdot 10^5 ) is the number of cities, and m m (1m4105 1 \le m \le 4 \cdot 10^5 ) is the number of couriers that will be hired. Couriers are numbered 1 to m m , in the order they are hired. This is followed by m m lines, the i i th of which contains two distinct integers ai a_i and bi b_i (1ai,bin 1 \le a_i, b_i \le n ), denoting the home and destination cities, respectively, for courier i i .

输出格式

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

4 4
1 2
2 3
4 3
4 2
1
2
4
6

提示

Explanation of Sample 1:

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