favorite We need a little bit of your help to keep things running, click on this banner to learn more

Strong Connected Components


The Chief Engineer Peter was asked to develop a new model of aircraft for the company "Air Bubundiya". It was found that the hardest part is choosing the optimal size of the fuel tank.

The Chief Cartographer of "Air Bubundiya" John has made a detailed map of Bubundiya. On this map he marked the fuel consumption for the flight between each pair of cities.

Peter wants to make the size of fuel tank as small as possible, so that the aircraft can fly from any city to any other(possibly with refueling in cities on the way) .


The first line contains the number of cities n (1n1000) in Burbundiya. Each of the next n lines contains n numbers. The j-th number in the i-th line equals to fuel consumption during the flight from i-th city to the j-th. All numbers are nonnegative and less than 109. It is known that for any i the number at the i-th line and the i-th position is zero.


Print one number - the optimal size of the fuel tank.

Time limit 1 seconds
Memory limit 256 MiB
Input example #1
0 10 12 16
11 0 8 9
10 13 0 22
13 10 17 0
Output example #1
Author Vitaly Goldstein
Source Winter School, Kharkov, 2011, Day 9