#K37672. Minimum Train Scheduling Time
Minimum Train Scheduling Time
Minimum Train Scheduling Time
You are given a railway network consisting of n stations and m bidirectional tracks. Each track connects two distinct stations and has an associated travel time. The goal is to determine the minimum total time required to ensure that all stations are connected, i.e. every station is reachable from every other station, under the constraint that no two trains use the same track simultaneously.
This problem can be modeled as finding the Minimum Spanning Tree (MST) of a connected, weighted graph. The sum of the weights of the edges in the MST represents the minimum scheduling time required.
You are asked to implement a solution that reads the number of stations and tracks, followed by the list of tracks with their travel times, and computes the total minimum time.
inputFormat
The first line contains two space-separated integers n and m, representing the number of stations and the number of tracks respectively.
The following m lines each contain three space-separated integers: u, v, and w, where u and v are the connected stations (1-indexed) and w is the travel time of the track between them.
outputFormat
Output a single integer — the minimum total scheduling time which is the sum of the travel times of the tracks in the minimum spanning tree.
## sample4 4
1 2 5
1 3 10
2 4 3
3 4 4
12
</p>