Roads are not a luxury but a way to travel
Time limit2sMemory limit1024 MB
After each one-way road is added to a DAG, find the fewest vertex-disjoint routes that together visit every city exactly once.
Problem
Country N has cities, numbered from 1 to , but it has no roads at all. The president has decided to build roads over days, one new road per day. To encourage migration, every road is one-way, and the road network is planned so that if there is a path from city to city , there is no path from city to city .
To promote the new roads, country N holds a series of test drives through its cities every day. Each car starts in some city, drives along the roads built so far, and ends in some city. A car may start and end in the same city, in which case it drives no roads. To please residents and save drivers' fuel, the organizers choose the set of routes each day under these rules:
- Every city must be visited by a car. A city counts as visited if it is the start, the end, or an intermediate city of any car's route.
- No city may be visited more than once by the cars.
- The total number of cars used must be minimal.
The transport ministry of country N has already scheduled the construction of exactly one road for each of the next days. For each day, the ministry asks you to find the minimum number of cars needed for the test drives. On day , all roads built on days are available.
Input
The first line contains two integers and (, ), the number of cities and the number of days. Each of the next lines contains two integers and (, ), meaning that on day a one-way road from city to city is built. A road may be built between two cities that are already connected by a road. It is guaranteed that after each road is built, if there is a path from city to city , then there is no path from city to city .
Output
Print numbers. The -th number is the minimum number of cars needed after the first roads are built.
Hint
In the first example, even after the first two roads are built, at least two cars are still needed. For instance, one car can drive from city 1 to city 2, and another car can start and finish in city 3. After all roads are built, one car is enough: it drives along .
In the second example, after all roads are built, two cars could visit all cities, but the rule that no city may be visited more than once rules this out.