int a[N][N];
int dist[N];
bool vis[N] = {};
int src, dst, temp;
src = 0;
vis[src] = true;
temp = Max;
int MST;
for(int i = 0; i < N; ++ i)
dist[i] = i == src ? Max : a[i][src];
for(int t = 0; t < N - 1; ++ t){
temp = Max;
for(int i = 0; i < N; ++ i){
if(vis[i])
continue;
if(dist[i] < temp){
temp = dist[i];
dst = i;
}
}
for(int i = 0; i < N; ++ i){
dist[i] = min(dist[i], a[dst][i]);
}
MST += temp;
}