#P1137. 旅行计划
旅行计划
Description
Xiao Ming is going to travel to a country. This country has cities, numbered to , and there are roads connecting them. Xiao Ming plans to start from some city and only move east until he stops at city .
Therefore, for each city , he needs to choose a starting city and plan a route ending at city , such that along the route, except for the first city, every city lies to the east of the previous city. Under this condition, he also wants to visit as many cities as possible.
You only know the relative east–west positions of the two cities connected by each road, but you do not know the exact positions of all cities. Now, for every , you need to plan a route for Xiao Ming and compute the maximum number of cities that can be visited on a route ending at city .
Input Format
The first line contains two positive integers .
The next lines each contain two positive integers , indicating there is a road connecting city and city , and it is guaranteed that city is to the west of city .
Output Format
Output lines. The -th line contains a positive integer, the maximum number of cities that can be visited on a route ending at city .
5 6
1 2
1 3
2 3
2 4
3 4
2 5
1
2
3
4
3
Hint
Choosing to always start from city yields the answers.
Constraints:
- For of the testdata, .
- For of the testdata, .
- For of the testdata, , .
Translated by ChatGPT 5
京公网安备 11011102002149号