Train Fare
Time limit2.5sMemory limit256 MB
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.
- Level
Medium7 of 10
- Topics
- BFS, Shortest path, Graph
- Solved
- No attempts yet
Problem
The country of JOI has cities, numbered through . City is the capital.
JOI has exactly one railway company, and that company runs lines, numbered through . Line () connects city and city 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 years. At the start of year () of the plan, the fare of line 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 () is therefore taken in the state where exactly the lines have been raised and no other line has. In the year survey, a resident of city () is unhappy with the company if and only if the following condition holds.
- The minimum cost of travelling from city to the capital, city , under the fares in force at that time is larger than the minimum cost of travelling from city to city under the fares in force before the plan started.
The cost of a trip that uses several lines is the sum of the fares of those lines. Residents of city 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.
Input
Read the following data from standard input.
- The first line contains three integers , , separated by spaces. JOI has cities and lines, and the fare increase plan runs for years.
- Each of the next lines contains two integers. Line of them () contains and separated by a space, meaning that line connects city and city .
- Each of the next lines contains one integer. Line of them () contains , meaning that the fare of line is raised in year of the plan.
Output
Print lines to standard output. Line () must contain the number of cities that contain unhappy residents in the year survey.
Constraints
- ()
- ()
- ()
- ()
- ()
- At most one line directly connects any two cities.
- Every city can reach city by using one or more lines.