402839: GYM100917 F Find the Length

Memory Limit:256 MB Time Limit:0 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

F. Find the Lengthtime limit per test4 seconds (5 seconds for Java)memory limit per test256 megabytesinputstandard inputoutputstandard output

For each vertice of given undirected weighted graph calculate the length of shortest simple cycle, which contains this vertice.

Input

First line of the input contains one inteter n — number of vertices in the graph (1 ≤ n ≤ 300).

Each of n lines contain n integers, i-th integer in the i-th column is equal to 0 for any i. If for i ≠ j j-th integer in i-th line aij is equal to  - 1, then vertices i and j are not connected, otherwise they are connected by the edge of weight aij (1 ≤ aij ≤ 106).

You may assume that graph does not contain self-loops and aij = aji for any 1 ≤ i, j ≤ n.

Output

Print n integers one per line. i-th of those integers must be lentgh of the shortest simple cycle, containig i-th vertice. If no simple cycles contain i-th vertiex, print  - 1 at corresponding line.

ExamplesInput
4
0 9 1 1
9 0 -1 1
1 -1 0 -1
1 1 -1 0
Output
11
11
-1
11

加入题单

算法标签: