import java.util.Scanner;
public class 最短路径 {
static int a;
static int sum = 0;
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
a = sc.nextInt();
long[][] b = new long[a][a];
for (int i = 0; i < a; i++) {
for (int j = 0; j < a; j++) {
b[i][j] = sc.nextLong();
}
}
s(b);
}
private static void s(long[][] b) {
int k = 0;// 记录下标
boolean isgetPath[] = new boolean[b.length];
Long[] c = new Long[b[0].length];
for (int v = 0; v < b.length; v++) {
c[v] = b[0][v];// 获取v0这一行的权值数组
}
c[0] = (long) 0;
isgetPath[0] = true;
for (int v = 1; v < b.length; v++) {
long min = 1000000;
for (int w = 0; w < b.length; w++) {
if (!isgetPath[w] && c[w] < min) {
k = w;
min = c[w];
}
}
isgetPath[k] = true;
for (int j = 0; j < b.length; j++) {
if (!isgetPath[j] && (min + b[k][j] < c[j])) {
c[j] = min + b[k][j];
}
}
}
for (int i = 1; i < a; i++) {
System.out.println("V0到V" + i + "的最短路径为:" + c[i] + "\n");
}
}
}
public class 最短路径 {
static int a;
static int sum = 0;
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
a = sc.nextInt();
long[][] b = new long[a][a];
for (int i = 0; i < a; i++) {
for (int j = 0; j < a; j++) {
b[i][j] = sc.nextLong();
}
}
s(b);
}
private static void s(long[][] b) {
int k = 0;// 记录下标
boolean isgetPath[] = new boolean[b.length];
Long[] c = new Long[b[0].length];
for (int v = 0; v < b.length; v++) {
c[v] = b[0][v];// 获取v0这一行的权值数组
}
c[0] = (long) 0;
isgetPath[0] = true;
for (int v = 1; v < b.length; v++) {
long min = 1000000;
for (int w = 0; w < b.length; w++) {
if (!isgetPath[w] && c[w] < min) {
k = w;
min = c[w];
}
}
isgetPath[k] = true;
for (int j = 0; j < b.length; j++) {
if (!isgetPath[j] && (min + b[k][j] < c[j])) {
c[j] = min + b[k][j];
}
}
}
for (int i = 1; i < a; i++) {
System.out.println("V0到V" + i + "的最短路径为:" + c[i] + "\n");
}
}
}