貌似就是个裸的最小生成树啊
*******************************************************************************
#include<iostream>
#include<cstring>
#include<cstdio>
#include<queue>
#include<math.h>
#include<vector>
#include<algorithm>
using namespace std; const int maxn = ;
const int oo = 0xfffffff; int G[maxn][maxn]; int prim(int N)
{
int i, j, dist[maxn]={}, use[maxn]={, }; for(i=; i<=N; i++)
dist[i] = G[][i];
for(i=; i<N; i++)
{
int k = , Min = oo; for(j=; j<=N; j++)
{
if(!use[j] && Min > dist[j])
Min = dist[j], k = j;
} use[k] = true; for(j=; j<=N; j++)
if(!use[j])dist[j] = min(dist[j], G[k][j]);
} int ans = ; for(i=; i<=N; i++)
ans += dist[i]; return ans;
} int main()
{
int N; while(scanf("%d", &N) != EOF)
{
for(int i=; i<=N; i++)
for(int j=; j<=N; j++)
{
scanf("%d", &G[i][j]);
} int ans = prim(N); printf("%d\n", ans);
} return ;
}