#include <iostream>
#include <string>
#include "math.h"
using namespace std;
const int maxn = 100;
const int maxint = 99999;
void Fun(int n, int v, int *dist, int *prev, int c[maxn] [maxn] )
{
bool s[maxn] ; // 判断是否已存入该点到S集合中
for(int i=1; i<=n; ++i)
{
dist[i] = c[v] [i] ;
s[i] = 0; // 初始都未用过该点
if(dist[i] == maxint)
prev[i] = 0;
else
prev[i] = v;
}
dist[v] = 0;
s[v] = 1;
for(int i=2; i<=n; ++i)
{
int tmp = maxint;
int u = v;
for(int j=1; j<=n; ++j)
if((!s[j] ) && dist[j] <tmp)
{
u = j;
tmp = dist[j] ;
}
s[u] = 1;
for(int j=1; j<=n; ++j)
if((!s[j] ) && c[u] [j] <maxint)
{
int newdist = dist[u] + c[u] [j] ;
if(newdist < dist[j] )
{
dist[j] = newdist;
prev[j] = u;
}
}
}
}
int main()
{
int dist_min[maxn] ;
int ppp[maxn] ;
int c[maxn] [maxn] ;
int n;
int workdis;
cin >> n;
cin>>workdis;
for(int i=1; i<=n; ++i)
dist_min[i] = maxint;
for(int i=1; i<=n; ++i)
for(int j=1; j<=n; ++j)
cin>>c[i] [j] ;
Fun(n, 1, dist_min, ppp, c);
cout<<dist_min[workdis+1];
return 0;
}
#include <string>
#include "math.h"
using namespace std;
const int maxn = 100;
const int maxint = 99999;
void Fun(int n, int v, int *dist, int *prev, int c[maxn] [maxn] )
{
bool s[maxn] ; // 判断是否已存入该点到S集合中
for(int i=1; i<=n; ++i)
{
dist[i] = c[v] [i] ;
s[i] = 0; // 初始都未用过该点
if(dist[i] == maxint)
prev[i] = 0;
else
prev[i] = v;
}
dist[v] = 0;
s[v] = 1;
for(int i=2; i<=n; ++i)
{
int tmp = maxint;
int u = v;
for(int j=1; j<=n; ++j)
if((!s[j] ) && dist[j] <tmp)
{
u = j;
tmp = dist[j] ;
}
s[u] = 1;
for(int j=1; j<=n; ++j)
if((!s[j] ) && c[u] [j] <maxint)
{
int newdist = dist[u] + c[u] [j] ;
if(newdist < dist[j] )
{
dist[j] = newdist;
prev[j] = u;
}
}
}
}
int main()
{
int dist_min[maxn] ;
int ppp[maxn] ;
int c[maxn] [maxn] ;
int n;
int workdis;
cin >> n;
cin>>workdis;
for(int i=1; i<=n; ++i)
dist_min[i] = maxint;
for(int i=1; i<=n; ++i)
for(int j=1; j<=n; ++j)
cin>>c[i] [j] ;
Fun(n, 1, dist_min, ppp, c);
cout<<dist_min[workdis+1];
return 0;
}