Taxi Trip
Time limit2sMemory limit1024 MB
On a weighted tree, find the minimum taxi fare from city 0 to every city, where each city's taxi has its own base fare and per-km rate.
- Level
Medium7 of 10
- Topics
- Tree, Dynamic programming, DFS
- Solved
- No attempts yet
Problem
The IOI country has cities and bidirectional roads connecting them, and any two different cities can be reached from each other using only roads. In other words, the road network of the IOI country forms a tree.
Each city has a distinct number from to , and city is the capital of the IOI country. For every , road connects city and city , and its length is km.
Taxi fares differ by city. For every , a taxi departing from city has a base fare of won and a per-kilometer fare of won. If you ride a taxi from city for km, you pay won.
Seohyun lives in city 0, the capital. She wants to travel to other cities by taxi. When she arrives at a city, she can keep riding her current taxi or switch to a taxi departing from that city. Switching taxis requires paying the base fare again, and the per-kilometer fare may change. For each city, compute the minimum cost to travel from city 0 to that city.
Constraints
- For all , ()
- For all , ()
- For all , ; ()
- For all , ()