#C5367. Minimum Communication Time

    ID: 49008 Type: Default 1000ms 256MiB

Minimum Communication Time

Minimum Communication Time

You are given a network of N computers and M bidirectional communication connections. Each connection is represented as a triple \( (u, v, w) \) which means there is a communication line between computer \( u \) and computer \( v \) with a communication time of \( w \). Your task is to compute the minimum communication time needed to send a message from computer 1 to computer \( N \). If there is no possible path between these two computers, output -1.

Note: The communication network is undirected, so every connection can be used in both directions.

Example: For \( N = 5 \) and the following connections:

1 2 3
1 3 2
2 4 4
3 4 1
4 5 2
2 5 7

The minimum communication time from computer 1 to computer 5 is \( 5 \).

inputFormat

The first line contains two integers \( N \) and \( M \), representing the number of computers and the number of communication connections, respectively.

Each of the next \( M \) lines contains three integers \( u \), \( v \) and \( w \) indicating that there is an undirected connection between computer \( u \) and computer \( v \) with a communication time of \( w \).

outputFormat

Output a single integer representing the minimum communication time required to send a message from computer 1 to computer \( N \). If no such path exists, output -1.

## sample
5 6
1 2 3
1 3 2
2 4 4
3 4 1
4 5 2
2 5 7
5