#BS0000470. Phí qua đường (The Toll! Revisited)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Phí qua đường (The Toll! Revisited)
The Toll! Revisited
Source: UVa
Version: Phuoc Hung OJ Extended
Problem Statement
Places in a bidirectional road network have single-letter English names. Uppercase names represent towns and lowercase names villages. Entering a village costs one item; entering a town with items costs items. Leaving is free, including at the start. Deliver items at the destination. Minimize the initial cargo; among optimal routes choose the lexicographically smallest name sequence, with uppercase before lowercase.
Input
Read roads, each represented by a pair of letters, then : the required delivery amount, start and destination.
Output
Print three lines: Case 1:, the minimum initial cargo, and the route with names separated by hyphens.
Subtasks
Subtask 1 (20 points)
- , ; counts distinct names including ; a route from to exists; names are English letters.
Subtask 2 (30 points)
- , ; counts distinct names including ; a route from to exists; names are English letters.
Subtask 3 (50 points)
- , ; counts distinct names including ; a route from to exists; names are English letters.
Examples
Example 1
Input
1
a Z
19 a Z
Output
Case 1:
20
a-Z
Explanation
Entering Z with 20 items costs one.
Example 2
Input
5
A D
D X
A b
b c
c X
39 A X
Output
Case 1:
44
A-b-c-X
Explanation
44 items become 43, 42 and 39; the route through D requires 45.