#K93707. Minimum Latency

    ID: 38479 Type: Default 1000ms 256MiB

Minimum Latency

Minimum Latency

Given a network of computers represented as an undirected weighted graph with n nodes and m edges, your task is to determine the minimum latency required to send a message from a source computer S to a destination computer D.

The graph is defined by m edges. Each edge is given as a tuple (u, v, l), indicating there is an edge connecting nodes u and v with latency l. If no path exists between S and D, output -1.

Note: The nodes are numbered from 1 to n and the input is designed such that Dijkstra’s algorithm can be applied for an efficient solution.

inputFormat

The first line contains four integers: n, m, S, D, where:

• n is the number of nodes. • m is the number of edges. • S is the source node. • D is the destination node.

The following m lines each contain three integers u, v, and l, representing an edge between nodes u and v with latency l. If m equals 0, there will be no additional lines.

outputFormat

Output a single integer that represents the minimum latency required to send a message from node S to node D. If there is no valid path, output -1.## sample

4 4 1 4
1 2 4
2 3 1
3 4 5
1 4 10
10

</p>