PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#FW0000053. Đường quê (Country Roads)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Đường quê (Country Roads)
Country Roads
Source: LightOJ
Version: Phuoc Hung OJ Extended
Problem Statement
For each city in an undirected weighted road network, find a route to the home city t that minimizes the maximum edge cost on the route. A city may be unreachable.
Input
First n m; then m lines u v w (0-based), then t.
Output
Print n lines in city order 0..n-1: the minimum maximum edge cost, or exactly Impossible.
Subtasks
- Subtask 1 (40 points): . Indices are 0-based, 0 <= u,v,t < n and u != v. Roads are undirected; parallel roads and disconnected components are allowed.
- Subtask 2 (60 points): . Indices are 0-based, 0 <= u,v,t < n and u != v. Roads are undirected; parallel roads and disconnected components are allowed.
Examples
Input
4 3
0 1 8
1 2 4
0 2 10
0
Output
0
8
8
Impossible
Explanation
City 0 costs 0. City 1 reaches it with bottleneck 8. City 2 uses 2–1–0, with max(4,8)=8, better than the direct weight 10. City 3 is disconnected.