#include<bits/stdc++.h>
#define mx 1000
#define inf 1e8
using namespace std;
typedef long long ll;
ll graph[mx][mx];
int main()
{
ll i,j,k,l,m,n,edge,node;
cin>>edge>>node;
for(i=0;i<mx;i++)
{
for(j=0;j<mx;j++)
{
graph[i][j]=inf;
}
}
for(i=1;i<=edge;i++)
{
graph[i][i]=0;
}
for(i=1;i<=edge;i++)
{
ll a,b,cost;
cin>>a>>b;
cin>>cost;
graph[a][b]=cost;
}
for(k=1;k<=node;k++)
{
for(i=1;i<=node;i++)
{
for(j=1;j<=node;j++)
{
graph[i][j]=min(graph[i][j],graph[i][k]+graph[k][j]);
}
}
}
for(i=1;i<=node;i++)
{
for(j=1;j<=node;j++)
{
if(graph[i][j]!=inf)
{
cout<<i<<" "<<j<<" "<<graph[i][j]<<endl;
}
}
}
return 0;
}
#define mx 1000
#define inf 1e8
using namespace std;
typedef long long ll;
ll graph[mx][mx];
int main()
{
ll i,j,k,l,m,n,edge,node;
cin>>edge>>node;
for(i=0;i<mx;i++)
{
for(j=0;j<mx;j++)
{
graph[i][j]=inf;
}
}
for(i=1;i<=edge;i++)
{
graph[i][i]=0;
}
for(i=1;i<=edge;i++)
{
ll a,b,cost;
cin>>a>>b;
cin>>cost;
graph[a][b]=cost;
}
for(k=1;k<=node;k++)
{
for(i=1;i<=node;i++)
{
for(j=1;j<=node;j++)
{
graph[i][j]=min(graph[i][j],graph[i][k]+graph[k][j]);
}
}
}
for(i=1;i<=node;i++)
{
for(j=1;j<=node;j++)
{
if(graph[i][j]!=inf)
{
cout<<i<<" "<<j<<" "<<graph[i][j]<<endl;
}
}
}
return 0;
}
No comments:
Post a Comment