POJ 2485
//Prim算法求最小生成树
#include <iostream>
using namespace std;
#define arraysize 501
int maxData = 0x7fffffff; //设定最大值
int dis[arraysize][arraysize];
bool final[arraysize];
int d[arraysize];
int N;
void prim()
{
int maxmin = 0;
memset(final,0,sizeof(final));
memset(d,0,sizeof(d));
int v = 1;
for(int i=1;i<N+1;++i)
{
d[i] = dis[v][i];
}
d[v] = 0;
final[v] = true;
for(int i1=1;i1<N;++i1)
{
int min = maxData;
for(int i2=2;i2<N+1;++i2)
{
if(!final[i2] && d[i2]<min)
{
min = d[i2];
v = i2;
}
}
final[v] = true;
if(min>maxmin) //此处增加判断求最小生成树中边的最大值
maxmin = min;
for(int i3=2;i3<N+1;++i3)
{
if(!final[i3] && dis[v][i3]<d[i3])
{
d[i3] = dis[v][i3];
}
}
}
cout<<maxmin<<endl;
}
int main()
{
//freopen("1.txt","r",stdin);
int T;
cin>>T;
for(int i=0;i<T;++i)
{
cin>>N;
for(int i1=1;i1<N+1;++i1)
{
for(int i2=1;i2<N+1;++i2)
{
cin>>dis[i1][i2];
}
}
prim();
}
return 0;
}