#include<fstream>
using namespace std;
const int inf=15000;
int c[100][100],n;
ifstream f("date.in");
ofstream g("date.out");
void citire()
{ int i,j,x,y,cost;
f>>n;
for(i=1;i<=n;i++)
for(j=1;j<=n;j++)
if(i==j) c[i][j]=0;
else c[i][j]=inf;
for(i=1;i<n;i++)
{ f>>x>>y>>cost;
c[y][x]=c[x][y]=cost;
}
}
void rf()
{ int i,j,k;
for(k=1;k<=n;k++)
for(i=1;i<=n;i++)
for(j=1;j<=n;j++)
if(c[i][j]>c[i][k]+c[k][j])
c[i][j]=c[i][k]+c[k][j];
}
void afis()
{ int i,j;
for(i=1;i<=n;i++)
{ for(j=1;j<=n;j++)
g<<c[i][j]<<" ";
g<<endl;
}
}
int main()
{ citire();
rf();
afis();
f.close();
g.close();
return 0;
}
5
1 2 4
1 3 5
2 4 6
4 5 1
0 4 5 10 11
4 0 9 6 7
5 9 0 15 16
10 6 15 0 1
11 7 16 1 0
|