ICPC 2025 · Problem E · Delivery Service

49th ICPC · Baku, Azerbaijan

Statement

The Intercity Caspian Package Company (ICPC) is starting a delivery service which will deliver pack- ages 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 sched- ule: 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 pack- age 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 (1u<vn1\le u < v \le n).

Input

The first line of input contains two integers nn and mm, where nn (2n21052\le n\le 2\cdot 10^{5}) is the number of cities, and mm (1m41051\le m\le 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 aia_{i} and bib_{i} (1ai,bin1\le ai, bi \le n), 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, . . . , m couriers.

Sample Input 1

4 4
1 2
2 3
4 3
4 2

Sample Output 1

1
2
4
6

Explanation of Sample 1:

  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 33 delivers the package to city 44.

  1. After the fourth courier is hired, all six pairs of cities are connected.

No official solution in the source collection.