poj 2485 Highways(最小生成树,基础,最大边权)
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
//听说听木看懂之后,数据很水,我看看能不能水过 #define _CRT_SECURE_NO_WARNINGS #include<stdio.h> #include<string.h> #include<math.h> #include<algorithm> using namespace std; #define M 510 #define inf 999999999 int mat[M][M]; int prim(int n,int sta) { int ans=0,dis[M]; int mark[M],i,j; for(i=0;i<n;i++) { dis[i]=mat[sta][i]; mark[i]=0; } mark[sta]=1; for(i=1;i<n;i++) { int minn=inf; int flag=-1; for(j=0;j<n;j++) { if(minn>dis[j]&&mark[j]==0) { flag=j; minn=dis[j]; } } mark[flag]=1; ans=ans>dis[flag]? ans:dis[flag]; for(j=0;j<n;j++) { if(dis[j]>mat[flag][j]) dis[j]=mat[flag][j]; } } return ans; } int main() { int t,i,j,n; scanf("%d",&t); while(t--) { scanf("%d",&n); for(i=0;i<n;i++) { for(j=0;j<n;j++) { scanf("%d",&mat[i][j]); } } printf("%d\n",prim(n,0)); } return 0; }
一道又一道,好高兴!