Prim:
View Code
1 #include2 #include 3 #define MAX 99999 4 #define M 110 5 int dis[M] ; 6 int map[M][M] ; 7 bool vis[M] ; 8 void init() 9 {10 for(int i=0; i map[pos][j])42 {43 dis[j] = map[pos][j] ;44 }45 }46 }47 return sum ;48 }49 int main()50 {51 int a, b, c, n ;52 while(scanf("%d", &n), n)53 {54 init() ;55 for(int i=1; i<=n*(n-1)/2; i++)56 {57 scanf("%d%d%d", &a,&b, &c) ;58 if(map[a][b]>c)59 map[a][b] = map[b][a] = c ;60 }61 printf("%d\n", prim(n)) ;62 }63 return 0 ;64 }