#K8231. Maximum Water Flow
Maximum Water Flow
Maximum Water Flow
You are given a network of towns connected by bidirectional roads, where each road has a fixed water capacity. Town 1 is the capital, and water is delivered from the capital to all other towns. For each town (from town 2 to town n), determine the maximum possible water flow that can be delivered along the unique path from the capital. The water flow to a town is limited by the smallest capacity (bottleneck) on the path from the capital to that town.
In other words, for each town i (i = 2, 3, ..., n), if the unique path from town 1 to town i has roads with capacities \(c_1, c_2, \ldots, c_k\), then the maximum water flow to town i is given by:
[ \text{flow}(i) = \min{ c_1, c_2, \ldots, c_k } ]
If there is only the capital, output nothing.
inputFormat
The input is read from stdin and has the following format:
- An integer
n
(\(1 \leq n \leq 10^5\)) denoting the number of towns. Ifn = 1
, then no further input is provided. - For
n > 1
, exactlyn - 1
lines follow. Each line contains three integersu
,v
, andc
, representing a bidirectional road between townsu
andv
with water capacityc
(\(1 \leq c \leq 10^9\)).
outputFormat
Print the maximum water flow values for towns 2 to n
on a single line, separated by spaces. If there is no town other than the capital, print nothing.
5
1 2 10
1 3 5
2 4 7
3 5 4
10 5 7 4