题目链接:http://acm.pku.edu.cn/JudgeOnline/problem?id=1287
const int MAX_VETEX_NUM = 100;
int nPoints,nRoutes;//点的个数,边的个数
int route[MAX_VETEX_NUM][MAX_VETEX_NUM]; //图
int closedge[MAX_VETEX_NUM];
int v[MAX_VETEX_NUM];//选择的顶点集
for(i = 1;i <= nPoints; ++i)
closedge[i] = route[1][i];
for(i = 1;i <= nPoints; ++i)
int min = numeric_limits<int>::max();
for(j = 1;j <= nPoints; ++j)
if(!v[j] && closedge[j] && (closedge[j] < min))
if(min != numeric_limits<int>::max())
if(!v[j] && route[k][j] &&((route[k][j] < closedge[j]) || closedge[j]==0))
closedge[j] = route[k][j];
while(cin >> nPoints && nPoints != 0)
memset(route,0,sizeof(route));
for(i = 1;i <= nRoutes; ++i)
cin >> p1 >> p2 >> nCost;
if (nCost < route[p1][p2])
route[p1][p2] = route[p2][p1] = nCost;
route[p1][p2] = route[p2][p1] = nCost;
本文转自Phinecos(洞庭散人)博客园博客,原文链接:http://www.cnblogs.com/phinecos/archive/2009/09/12/1565282.html,如需转载请自行联系原作者