Start

2019-10-27 16:00 UTC

Problem Set 5

End

2019-11-11 16:00 UTC
The end is near!
Session is over.
Not yet started.
Session is starting in -43 days 0:33:24

Time elapsed

360:00:00

Time remaining

0:00:00

Problem C
Driving Range

These days, many carmakers are developing cars that run on electricity instead of gasoline. The batteries used in these cars are generally very heavy and expensive, so designers must make an important tradeoffs when determining the battery capacity, and therefore the range, of these vehicles. Your task is to help determine the minimum range necessary so that it is possible for the car to travel between any two cities on the continent.

The road network on the continent consists of cities connected by bidirectional roads of different lengths. Each city contains a charging station. Along a route between two cities, the car may pass through any number of cities, but the distance between each pair of consecutive cities along the route must be no longer than the range of the car. What is the minimum range of the car so that there is a route satisfying this constraint between every pair of cities on the continent?

Input

The first line of the input contains two nonnegative integers $n$ and $m$, the number of cities and roads. Each of these integers is no larger than one million. The cities are numbered from 0 to $n-1$. The first line is followed by $m$ more lines, each describing a road. Each such line contains three non-negative integers. The first two integers are the numbers of the two cities connected by the road. The third integer is the length of the road, a positive integer no larger than $10^9$.

Output

For each road network, output a line containing one integer, the minimum range of the car that enables it to drive from every city to every other city. If it is not possible to drive from some city to some other city regardless of the range of the car, instead output a line containing the word IMPOSSIBLE.

Sample Input 1 Sample Output 1
3 3
0 1 3
1 2 4
2 1 5
4
Sample Input 2 Sample Output 2
2 0
IMPOSSIBLE