#include<iostream>
using namespace std;
#include<math.h>
long int graph[1000][1000];
long int graph2[1000][1000];
int stack[1000];
int s1;
int v;
int n=0;
void path(int x, int y, long int k)
{
int flag,flag2;
long int t;
if(x==y)
{
if(graph2[stack[0]][y]<k)
graph2[stack[0]][y]=k;
return;
}
else
{stack[s1]=x;
s1++;
flag=0;
for(int d=0;d<v;d++)
{
if(graph[x][d]!=-1)
{flag2=0;
for(int f=0;f<s1;f++)
{
if(stack[f]==d)
flag2=1;
}
if(flag2==0)
{
if((graph[x][d]<k)||(k==-1))
{
t=graph[x][d];
path(d,y,t);
}
else
path(d,y,k);
}
}
}
s1--;
}
return;
}
int main()
{
int a,b ,c,d,i,j;
int x,y;
long int z;
int e,e1;
int s1=0;
long int n=-1;
cin>>v>>e;
e1=e;
/*initialise*/
for(i=0;i<v;i++)
{
for(j=0;j<v;j++)
graph[i][j]=-1;
}
/*input*/
while(e1--)
{
cin>>x>>y>>z;
graph[x][y]=z;
graph[y][x]=z;
}
/* for(i=0;i<v;i++)
{
for(j=0;j<v;j++)
cout<<graph[i][j]<<"\t";
cout<<endl;
}*/
for(i=0;i<v;i++)
{
for(j=0;j<v;j++)
{
if(i==j)
graph2[i][j]=0;
else
{
graph2[i][j]=-1;
path(i,j,n);
}
}
}
for(i=0;i<v;i++)
{
for(j=0;j<v;j++)
cout<<graph2[i][j]<<"\t";
cout<<endl;
}
//system("pause");
return 0;
}
I2luY2x1ZGU8aW9zdHJlYW0+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CiNpbmNsdWRlPG1hdGguaD4KCmxvbmcgaW50IGdyYXBoWzEwMDBdWzEwMDBdOwpsb25nIGludCBncmFwaDJbMTAwMF1bMTAwMF07CmludCBzdGFja1sxMDAwXTsKaW50IHMxOwppbnQgdjsKCmludCBuPTA7Cgp2b2lkIHBhdGgoaW50IHgsIGludCB5LCBsb25nIGludCBrKQp7CiAgICAgaW50IGZsYWcsZmxhZzI7CiAgICAgbG9uZyBpbnQgdDsKICAgICBpZih4PT15KQogICAgIHsKICAgICAgICAgICAgIGlmKGdyYXBoMltzdGFja1swXV1beV08aykKICAgICAgICAgICAgIGdyYXBoMltzdGFja1swXV1beV09azsKICAgICAgICAgICAgIHJldHVybjsKICAgICB9CiAgICAgICAgICAgICAKICAgICBlbHNlCiAgICAgIHtzdGFja1tzMV09eDsKICAgICAgczErKzsKICAgICAgZmxhZz0wOwogICAgICBmb3IoaW50IGQ9MDtkPHY7ZCsrKQogICAgICB7CiAgICAgICAgICAgICBpZihncmFwaFt4XVtkXSE9LTEpCiAgICAgICAgICAgICB7ZmxhZzI9MDsKICAgICAgICAgICAgICAgICAgICAgIGZvcihpbnQgZj0wO2Y8czE7ZisrKQogICAgICAgICAgICAgICAgICAgICAgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICBpZihzdGFja1tmXT09ZCkKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgZmxhZzI9MTsKICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgIGlmKGZsYWcyPT0wKQogICAgICAgICAgICAgICAgICAgICAgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgaWYoKGdyYXBoW3hdW2RdPGspfHwoaz09LTEpKQogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHQ9Z3JhcGhbeF1bZF07CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgcGF0aChkLHksdCk7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGVsc2UKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHBhdGgoZCx5LGspOwogICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgfQogICAgICB9CiAgICAgIHMxLS07CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIAogICAgICB9CiAgICAgCiAgICAgcmV0dXJuOwp9CgoKCgppbnQgbWFpbigpCnsKICAgIGludCBhLGIgLGMsZCxpLGo7CiAgICBpbnQgeCx5OwogICAgbG9uZyBpbnQgejsKICAgIGludCBlLGUxOwogICAgaW50IHMxPTA7CiAgICBsb25nIGludCBuPS0xOwogICAgY2luPj52Pj5lOwogICAgZTE9ZTsKICAgIC8qaW5pdGlhbGlzZSovCiAgICBmb3IoaT0wO2k8djtpKyspCiAgICB7CiAgICAgICAgICAgICAgICAgICAgZm9yKGo9MDtqPHY7aisrKQogICAgICAgICAgICAgICAgICAgIGdyYXBoW2ldW2pdPS0xOwogICAgfQogICAgLyppbnB1dCovCiAgICB3aGlsZShlMS0tKQogICAgewogICAgICAgICAgICAgICBjaW4+Png+Pnk+Pno7CiAgICAgICAgICAgICAgIGdyYXBoW3hdW3ldPXo7CiAgICAgICAgICAgICAgIGdyYXBoW3ldW3hdPXo7CiAgICAgfQogICAgLyogZm9yKGk9MDtpPHY7aSsrKQogICAgewogICAgICAgICAgICAgICAgICAgIGZvcihqPTA7ajx2O2orKykKICAgICAgICAgICAgICAgICAgICBjb3V0PDxncmFwaFtpXVtqXTw8Ilx0IjsKICAgICAgICAgICAgICAgICAgICBjb3V0PDxlbmRsOwogICAgfSovCiAgICAgCiAgICAgCiAgICAgZm9yKGk9MDtpPHY7aSsrKQogICAgIHsKICAgICAgICAgICAgICAgICAgICAgZm9yKGo9MDtqPHY7aisrKQogICAgICAgICAgICAgICAgICAgICB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBpZihpPT1qKQogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgZ3JhcGgyW2ldW2pdPTA7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBlbHNlCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgZ3JhcGgyW2ldW2pdPS0xOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHBhdGgoaSxqLG4pOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgfQogICAgIH0KICAgICBmb3IoaT0wO2k8djtpKyspCiAgICAgewogICAgICAgICAgICAgICAgICAgICBmb3Ioaj0wO2o8djtqKyspCiAgICAgICAgICAgICAgICAgICAgIGNvdXQ8PGdyYXBoMltpXVtqXTw8Ilx0IjsKICAgICAgICAgICAgICAgICAgICAgY291dDw8ZW5kbDsKICAgICB9CiAgICAgLy9zeXN0ZW0oInBhdXNlIik7CiAgICAgcmV0dXJuIDA7CiAgICAgfQogICAgIA==