#include<iostream>
#define N 100
#define MAXV 1000000
using namespace std;
/*
city[i][j]代表从城市i到城市j的花费
10
0 5 6 7 0 0 0 0 0 0
0 0 0 0 1 2 0 0 0 0
0 0 0 0 3 6 7 0 0 0
0 0 0 0 0 2 6 0 0 0
0 0 0 0 0 0 0 7 0 0
0 0 0 0 0 0 0 5 3 0
0 0 0 0 0 0 0 2 0 0
0 0 0 0 0 0 0 0 0 4
0 0 0 0 0 0 0 0 0 6
0 0 0 0 0 0 0 0 0 0
*/
int city[N][N];
//打印路线图
void print(int n){
if(n==0){
cout<<n;
return;
}
int i;
for(i=n-1;i>=0;i--){
if(city[i][n]==0) continue;
int cost = city[0][n]-city[0][i];
if(cost==city[i][n]) break;
}
fun(i);
cout<<"->"<<n;
}
int main(){
int n;
cin>>n;
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
cin>>city[i][j];
}
}
//计算从城市0到城市i的最小花费
for(int i=1;i<n;i++){
int min = MAXV;
//计算从城市0到城市j,再从城市j到城市i的最小花费
for(int j=0;j<i;j++){
if(city[j][i]==0) continue;
int temp = city[0][j]+city[j][i];
min = temp<min?temp:min;
}
city[0][i] = min;
}
for(int i=0;i<n;i++){
cout<<city[0][i]<<" ";
}
cout<<endl;
print(9);
cout<<endl;
return 0;
}