# find the mincost route

Time Limit: 1000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 4348    Accepted Submission(s): 1746

Problem Description

Input

Output

Sample Input
3 3 1 2 1 2 3 1 1 3 1 3 3 1 2 1 1 2 3 2 3 1

Sample Output
3 It's impossible.

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<queue>
#include<functional>
#define INF 0xfffffff
using namespace std;
int map[105][105];
int dis[105][105];
int ans;
void floyd(int m)
{
for(int k = 1 ; k <= m ; k++)
{
for(int i = 1 ; i <= k ; i++)
for(int j = 1 ; j < i ; j++)
if(ans > dis[i][j] + map[i][k] + map[k][j])
ans = dis[i][j] + map[i][k] + map[k][j];
for(int i = 1 ; i <= m ; i++)
for(int j = 1 ; j <= m ; j++)
if(dis[i][j] > dis[i][k] + dis[k][j])
dis[i][j] = dis[i][k] + dis[k][j];
}
}
int main()
{
int n,l;
while(~scanf("%d%d",&n,&l))
{
for(int i = 1 ; i <= n ; i++)
for(int j = 1 ; j <= n ; j++){
map[i][j] = INF;
dis[i][j] = INF;
}
int a,b,c;
for(int i = 0 ; i < l ; i++)
{
scanf("%d%d%d",&a,&b,&c);
if(dis[a][b] > c){
map[a][b] = map[b][a] = c;
dis[a][b] = dis[b][a] = c;
}
}
ans = INF;
floyd(n);
if(ans == INF)
printf("It's impossible.\n");
else
printf("%d\n",ans);
}
return 0;
}


• 本文已收录于以下专栏：

举报原因： 您举报文章：hd 1599 find the mincost route（floyd） 色情 政治 抄袭 广告 招聘 骂人 其他 (最多只允许输入30个字)