#K49777. Shortest Transmission Time
Shortest Transmission Time
Shortest Transmission Time
You are given an undirected graph with n nodes and m edges. Each edge connects two nodes and has an associated positive weight. Your task is to determine the minimum transmission time between two specified nodes, A and B. If there is no valid path from A to B, output -1.
The problem can be mathematically formulated as follows:
Given a graph \(G=(V,E)\) with \(|V|=n\) and \(|E|=m\), and two vertices \(A, B \in V\), find the minimum value of \(\sum_{(u,v)\in P} w(u,v)\) over all paths \(P\) from \(A\) to \(B\). If no such path exists, return -1.
You are advised to use Dijkstra's algorithm to solve this problem efficiently.
inputFormat
The input is read from standard input (stdin) and has the following format:
- The first line contains four integers:
n
m
A
B
, wheren
is the number of nodes,m
is the number of edges,A
is the starting node, andB
is the destination node. - The next
m
lines each contain three integers:u
v
w
, representing an edge between nodesu
andv
with weightw
.
outputFormat
Output a single integer representing the minimum transmission time (path weight) from node A
to node B
. If there is no path between these nodes, output -1.
4 4 1 4
1 2 1
2 3 2
3 4 1
1 3 4
4