ICPC 2025 · Problem E · Delivery Service
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 and are connected if it is possible to deliver a package from city to city as well as from to . 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 that are connected ().
Input
The first line of input contains two integers and , where () is the number of cities, and () is the number of couriers that will be hired. Couriers are numbered to , in the order they are hired. This is followed by lines, the th of which contains two distinct integers and (), denoting the home and destination cities, respectively, for courier .
Output
Output integers, denoting the number of pairs of connected cities after hiring the first 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:
-
After the first courier is hired, cities and are connected.
-
After the second courier is hired, cities and are connected. Note, however, that cities and are still not connected. Even though there’s a courier moving between cities and , and a courier moving between cities and , they never meet each other.
-
After the third courier is hired, cities and are connected and cities and are connected. For example, one way to deliver a package from city to city is:
-
hand it to courier in city at 19:00;
-
the next day, courier arrives in city at 12:00, and hands the package to courier who is also in city ;
-
at 18:00, courier delivers the package to city .
- After the fourth courier is hired, all six pairs of cities are connected.
No official solution in the source collection.