The question is to find the longest side. When the Minimum Spanning Tree is generated, use a variable to save the maximum value.
// Prim Algorithm # Include <iostream> # include <memory. h> # define INF 1000000 # define max 200 using namespace STD; int main () {int arcs [Max] [Max]; bool isvisit [Max]; int min_weight [Max]; int N; INT cases; CIN> cases; while (cases --) {CIN> N; memset (isvisit, false, sizeof (isvisit )); for (INT I = 0; I <n; I ++) for (Int J = 0; j <n; j ++) cin> arcs [I] [J]; for (INT I = 0; I <n; I ++) min_weight [I] = arcs [0] [I]; isvisit [0] = true; int _ Min; int hold, result = 0, max_weight = 0; For (INT I = 1; I <n; I ++) {_ min = inf; for (Int J = 0; j <n; j ++) {If (! Isvisit [J] & min_weight [J] <_ min) {_ min = min_weight [J]; hold = J ;}} max_weight = max (max_weight, _ min ); result + = _ min; isvisit [hold] = true; For (Int J = 0; j <n; j ++) if (! Isvisit [J] & arcs [hold] [J] <min_weight [J]) min_weight [J] = arcs [hold] [J];} cout <max_weight <Endl; If (cases! = 0) cout <Endl;} return 0 ;}