highways:http://poj.org/problem?id=2485
To give you a graph of n vertices stored in the form of adjacency matrices, let you ask for its minimum spanning tree and find the weights of the largest edges in the spanning tree.
Train of thought: use prim to seek, judge condition to change on the line.
Ps:dis array initialization with memset has been re, I hope to know how the generous enlighten, thanks ~
More Wonderful content: http://www.bianceng.cnhttp://www.bianceng.cn/Programming/sjjg/
#include <stdio.h> #include <string.h> #define INF 0x3f3f3f3f int map[510][510];
int dis[510];
int n, m;
int min (int a, int b) {return a > b b:a;}
int Prim () {int min_ele, min_node;
for (int i = 1; I <= n; i++) {dis[i] = INF;
///here if using memset (DIS, INF, sizeof (DIS)), the words will always be re int r = 1;
int Ans = 0;
for (int i = 1; i < n; i++) {min_ele = INF;
DIS[R] =-1; for (int j = 1; J <= N; j +) {if (J!= R && Dis[j] >= 0) {di
S[j] = min (Dis[j], map[r][j]);
if (Dis[j] < Min_ele) {Min_ele = Dis[j];
Min_node = j;
}} R = Min_node;
if (Min_ele > ans) ans = min_ele;
return Ans;
} void Solve () {scanf ("%d", &m);
while (m--) {scanf ("%d", &n); memset (Map, 0, sizeof (map)); for (int i = 1; I <= n; i++) {for (int j = 1; J <= N; j +) {scanf ("%
D ", &map[i][j]);
} printf ("%d\n", Prim ());
int main () {Solve ()};
return 0; }