解题思路:floyd算法,为什么运行错误,求解注意事项:参考代码:
#include <iostream>
#define MAXSIZE 15
#define MAXNUM 10000
using
namespace
std;
int
main()
{
int
i,j,n,deal[MAXSIZE][MAXSIZE],t1,t2;
int
t, k,max_num = 0,sum = 0;
cin >> n;
for
(i=0;i<MAXSIZE;i++)
{
for
(j=0;j<MAXSIZE;j++)
deal[i][j]=MAXNUM;
}
for
(k = 1; k < n ; k++){
cin >> t1 >> t2 >> t;
deal[t1][t2] = t;
deal[t2][t1] = t;
}
for
(i = 1; i <= n;i++){
for
(j =1; j <= n;j++){
for
(k=1;k <= n;k++)
{
if
(i != j && deal[i][j] > deal[i][k] + deal[k][j])
deal[i][j] = deal[i][k] + deal[k][j];
}
}
}
for
(i = 1;i <= n;i++){
for
(j=1;j <= n;j++)
if
(deal[i][j] > max_num && i != j)
max_num = deal[i][j];
}
for
(i = 11;i<=11+max_num-1;i++)
{
sum+=i;
}
cout << sum <<
"
"
;
return
0;
}