PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#FW0000053. Đường quê (Country Roads)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Đườ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): 1≤n≤12, 0≤m≤30, 1≤w≤200001\le n\le 12,\ 0\le m\le 30,\ 1\le w\le 20000. 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): 1≤n≤500, 0≤m≤16000, 1≤w≤200001\le n\le 500,\ 0\le m\le 16000,\ 1\le w\le 20000. 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.