#K79037. Taco: Shortest Delay
Taco: Shortest Delay
Taco: Shortest Delay
You are given a network of N
servers and M
communication links. Each link connects two servers and has an associated delay. However, only the links with delay not exceeding a given threshold K
can be used.
Your task is to compute the minimum total delay required to send data from a source server S
to a target server T
. Formally, if a link connects servers Ai and Bi with delay Di, it can be used only if
\( D_i \le K \).
If there exists no valid path from S
to T
following the constraint, output -1
.
Hint: You may use Dijkstra's algorithm to solve this problem efficiently, considering only the allowed links.
inputFormat
The first line contains five integers: N M S T K
, where:
N
is the number of servers.M
is the number of communication links.S
is the source server.T
is the target server.K
is the maximum allowed delay for a link to be used.
Each of the following M
lines contains three integers: Ai Bi Di
, where the link connects server Ai
to server Bi
with a delay of Di
.
outputFormat
Output a single integer – the minimum total delay to send data from server S
to server T
using only links with delay \( \le K \). If it is impossible, output -1
.
4 5 1 4 3
1 2 2
2 3 1
3 4 2
1 3 5
2 4 4
5