#K64037. Minimum Latency
Minimum Latency
Minimum Latency
Problem Statement:
You are given a network of n computers connected by m bidirectional cables. Each cable has an associated latency value. Given the starting computer src and the destination computer dest, your task is to compute the minimum total latency required to travel from src to dest. If there is no valid path between the two, output -1.
This problem can be modeled as finding the shortest path in a weighted undirected graph. The latency of a path is the sum of the weights (latencies) along its edges. An efficient approach to solve this problem is by using Dijkstra's algorithm.
Mathematically, given a graph \(G=(V,E)\) with vertices \(V = \{1,2,\ldots,n\}\) and each edge \((u,v)\) having a weight \(w\), you are to determine the minimum value of the expression:
\( \min_{path \in G} \sum_{(u,v) \in path} w \)
inputFormat
Input Format:
The first line contains two integers, n and m, representing the number of computers and the number of cables, respectively.
Each of the next m lines contains three integers, u, v, and w, indicating a bidirectional cable between computers u and v with latency w.
The last line contains two integers, src and dest, representing the starting and destination computers.
outputFormat
Output Format:
Print a single integer representing the minimum latency from src to dest. If there is no valid path, print -1.
5 6
1 2 10
1 3 20
2 3 5
2 4 1
3 4 15
4 5 5
1 5
16