#C1835. Shortest Delivery Time
Shortest Delivery Time
Shortest Delivery Time
You are given a directed graph representing a network of people and the direct communication paths between them. Each edge in the graph is associated with a travel time. Your task is to compute the shortest time required to deliver a message from a source person to a target person.
If there is no path connecting the source to the target, output unreachable
.
The relationship between nodes and edges can be described by the following formula:
Given a directed edge from node \( u \) to node \( v \) with weight \( w \), the relaxation is performed as follows:
[ dist(v) = \min { dist(v),, dist(u) + w } ]
Use Dijkstra's algorithm to compute the shortest delivery times.
inputFormat
The input is read from stdin and has the following format:
T N M u1 v1 w1 u2 v2 w2 ... (M lines) source target ... (the above block repeats for each test case)
Where:
T
is the number of test case blocks in the input.- For each test case block, the first line contains two integers
N
(the number of people) andM
(the number of directed edges). - The next
M
lines each contain three integersu
,v
, andw
representing an edge fromu
tov
with travel timew
. - The last line of each block contains two integers
source
andtarget
.
outputFormat
For each test case block, output the shortest delivery time from the source to the target on a single line. If the target is unreachable from the source, output unreachable
.
2
5 6
1 2 2
2 3 4
3 4 1
4 5 7
5 3 2
2 5 5
1 4
4 5
1 2 3
1 3 2
2 4 4
3 4 1
4 2 1
1 4
7
3
</p>