After each yearly fare hike from 1 to 2 yen, report how many cities have a cheapest fare to city 1 above the original all-1-yen cost.
Medium7BFSShortest pathGraphNo attempts yetTime limit2.5sMemory limit256 MBThe country of JOI has N cities, numbered 1 through N. City 1 is the capital.
JOI has exactly one railway company, and that company runs M lines, numbered 1 through M. Line i (1≤i≤M) connects city Ui and city Vi in both directions. There is no way to travel between cities other than by rail. Every city is reachable from every other city by riding one or more lines.
At the moment every line charges a fare of 1 yen. The company is in financial trouble, so it has drawn up a plan to raise the fare on some lines over the next Q years. At the start of year j (1≤j≤Q) of the plan, the fare of line Rj goes up from 1 yen to 2 yen. A fare that has been raised stays at 2 yen from then on and is never raised again.
The company surveys the residents of each city once a year. Before the plan starts, the residents of every city are satisfied with the company, but a fare increase can make some residents unhappy.
Each year's survey is taken after that year's increase. The survey in year j (1≤j≤Q) is therefore taken in the state where exactly the lines R1,R2,…,Rj have been raised and no other line has. In the year j survey, a resident of city k (2≤k≤N) is unhappy with the company if and only if the following condition holds.
The cost of a trip that uses several lines is the sum of the fares of those lines. Residents of city 1 are never unhappy with the company. Note that a route achieving the minimum cost under the raised fares may differ from a route achieving the minimum cost before the plan started.
Given the railway lines of JOI and the fare increase plan, write a program that reports, for each survey, the number of cities that contain unhappy residents.
Read the following data from standard input.
Print Q lines to standard output. Line j (1≤j≤Q) must contain the number of cities that contain unhappy residents in the year j survey.