Minimum tree structure-premium Manaus

Source: Internet
Author: User

Import java.util.scanner;//Premium Manaus public class Main {static final int maxvex =65535;static final int Minvex =65535;public stat IC void Main (string[] args) {Mygrop p = new Mygrop (); Minspantree_frim (P);}   static void Minspantree_frim (Mygrop G) {int min, I, J, K; int[] Adjvex = new Int[maxvex];//Save the relevant anchor point to subscript int[] Lowcost =   New int[maxvex];//holds the weighted value of the edge between the relevant fixed points adjvex [0]=0;  V0 starting lowcost as the heel of the smallest number [0]=0; V0diyige Join//Initialize from operation for (I =1; i<g.a; i++) {Lowcost[i] = g.src[0][i];//Fill the No. 0 row of data in the 0-order matrix into Adjvex [i]=0;}//Construct min for (i=1 ;i<g.a; i++) {min = Minvex; j=1; k=0;//Traverse node while (J&LT;G.A) {//Self and self-wired if (lowcost[j]!=0 && lowcost[j] <min) {min = lowcost[j]; k=j;//found a smaller subscript} j + +; } System.out.println ("(" +adjvex[k]+ ")--" +lowcost[k]+ "-(" +k+ ")"); lowcost[k]=0;//set the weight to zero for (j=1;j<g.a;j++) {if (lowcost[j]!=0 && g.src[k][j]<lowcost[j]) {Lowcost[j] = G.SRC[K][J]; ADJVEX[J] =k; }}}}}class mygrop{final int minvex =65535;int a = 9;int src[][] = {{0,10,minvex, Minvex, minvex,11, Minvex, Minvex,minvex}, {10,0,18,minvex, Minvex, minvex,16,minvex,12}, {Minvex,18,0,22,minvex,minvex, minvex,minvex,8}, {minvex,minvex,22,0,20,minvex,minvex,16,21}, {Minvex,minvex,minvex,20,0,26,minvex,7,minvex}, { 11,minvex,minvex,minvex,26,0,17,minvex,minvex}, {Minvex,16,minvex,minvex,minvex,17,0,19,minvex}, {MINVEX,MINVEX, Minvex,16,7,minvex,19,0,minvex}, {minvex,12,8,21,minvex,minvex,minvex,minvex,0}};void SetFun () {Scanner Scan = new Scanner (system.in); int i=0;int J=0;while (i++<a) {while (j++<a) {src[i][j]=scan.nextint ();}}}


Minimum tree structure-premium Manaus

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.