#C1835. Shortest Delivery Time

    ID: 45084 Type: Default 1000ms 256MiB

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) and M (the number of directed edges).
  • The next M lines each contain three integers u, v, and w representing an edge from u to v with travel time w.
  • The last line of each block contains two integers source and target.

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.

## sample
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>