#C11845. Minimum Maximum Bike Lane
Minimum Maximum Bike Lane
Minimum Maximum Bike Lane
In this problem, you are given a map of a city represented as a graph with ( n ) intersections (nodes) and ( m ) roads (edges). Each road is bidirectional and has an associated length. The goal is to determine the minimum possible value of the maximum road length used in a route (or "bike lane") that connects all intersections. More formally, for each starting intersection ( s ), you can determine the cost to reach every other intersection where the cost of a path is defined as ( \max{w_1, w_2, \dots, w_k} ) for the edges on that path. The answer is the minimum among the maximum costs computed over all starting intersections. If there exists an intersection that cannot be reached from the starting point (i.e. the graph is disconnected), the answer should be reported as INF
.
The problem can be mathematically formulated as follows:
Let ( G = (V, E) ) be an undirected graph with ( |V| = n ) and ( |E| = m ), and let each edge ( e ) have a weight ( w(e) ). For a starting vertex ( s ), define the cost to reach vertex ( v ) as:
[ d(s,v) = \min_{P,\in,Paths(s,v)} \max_{e,\in,P} w(e) ]
Your task is to compute:
[ ans = \min_{s,\in,V} \max_{v\in V} d(s,v) ]
and print the result. If any vertex is unreachable from a starting vertex, treat the cost as infinite and output INF
.
inputFormat
The input is given from stdin and is formatted as follows:
n m u1 v1 w1 u2 v2 w2 ... um vm wm
where n
is the number of intersections, m
is the number of roads, and each of the next m
lines contains three integers u
, v
, and w
, representing a bidirectional road connecting intersections u
and v
with length w
.
outputFormat
Output a single line to stdout containing one integer, which is the minimum possible value of the maximum bike lane length needed to connect all intersections. If the graph is disconnected and not all intersections can be reached, output INF
.
4 5
1 2 8
1 3 5
2 3 6
2 4 7
3 4 9
7
</p>