Graph structure exercise-Minimum Spanning Tree
Graph structure exercise-Minimum Spanning Tree Time Limit: 1000 ms Memory limit: 65536 K any questions? Click Here ^_^ There are n cities, some of which can be built between cities, and the cost of building different roads is different. Now, we want to know how much it will cost to build a highway to connect all cities so that we can start in any city and reach any other city. The input contains multiple groups of data in the following format. The first line contains two integers, n m, representing the number of cities and the number of roads that can be built. (N <= 100) the remaining m rows have three positive integers, a B c, indicating that a highway can be built between City a and City B at the cost of c. Each output group occupies one row, with only the minimum output cost. Sample Input
3 21 2 11 3 11 0
Sample output
20
Prompt Source: Zhao liqiang sample program
# Include
# Include
# Include
# Define inf 999999int map [110] [110]; int vis [110]; int dis [110]; int sum; void prim (int n) {int I, j, k; int min; sum = 0; memset (vis, 0, sizeof (vis); for (I = 1; I <= n; I ++) dis [I] = map [1] [I]; vis [1] = 1; for (I = 2; I <= n; I ++) {min = inf; for (j = 1; j <= n; j ++) {if (min> dis [j] &! Vis [j]) {k = j; min = dis [j] ;}} vis [k] = 1; sum + = min; for (j = 1; j <= n; j ++) {if (map [k] [j]
Zookeeper