HDU 1599 find the mincost route
来源:互联网 发布:mac文稿无端占内存 编辑:程序博客网 时间:2024/06/03 15:59
find the mincost route
Time Limit: 1000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 4206 Accepted Submission(s): 1693
Problem Description
杭州有N个景区,景区之间有一些双向的路来连接,现在8600想找一条旅游路线,这个路线从A点出发并且最后回到A点,假设经过的路线为V1,V2,....VK,V1,那么必须满足K>2,就是说至除了出发点以外至少要经过2个其他不同的景区,而且不能重复经过同一个景区。现在8600需要你帮他找一条这样的路线,并且花费越少越好。
Input
第一行是2个整数N和M(N <= 100, M <= 1000),代表景区的个数和道路的条数。
接下来的M行里,每行包括3个整数a,b,c.代表a和b之间有一条通路,并且需要花费c元(c <= 100)。
接下来的M行里,每行包括3个整数a,b,c.代表a和b之间有一条通路,并且需要花费c元(c <= 100)。
Output
对于每个测试实例,如果能找到这样一条路线的话,输出花费的最小值。如果找不到的话,输出"It's impossible.".
Sample Input
3 31 2 12 3 11 3 13 31 2 11 2 32 3 1
Sample Output
3It's impossible.
Author
8600
Source
HDU 2007-Spring Programming Contest - Warm Up (1)
Recommend
8600 | We have carefully selected several similar problems for you: 1595 1142 1217 1054 1594
#include<stdio.h>#include<string.h>#include<algorithm>#define INF 0xfffffffusing namespace std;int map[1010][1010],dis[1010][1010];int n,m,minn;void spfa(){int i,j,k;for(k=1;k<=n;k++){for(i=1;i<k;i++){for(j=i+1;j<k;j++){minn=min(minn,map[i][k]+map[k][j]+dis[i][j]);}}for(i=1;i<=n;i++){for(j=1;j<=n;j++){dis[i][j]=min(dis[i][j],dis[i][k]+dis[k][j]);}}}}int main(){int i,j,a,b,c;while(scanf("%d%d",&n,&m)!=EOF){for(i=0;i<=n;i++)for(j=0;j<=n;j++){if(i==j)map[i][j]=dis[i][j]=0;elsemap[i][j]=dis[i][j]=INF;}for(i=0;i<m;i++){scanf("%d%d%d",&a,&b,&c);if(c<map[a][b])map[a][b]=map[b][a]=dis[a][b]=dis[b][a]=c;}minn=INF;spfa();if(minn>=INF)printf("It's impossible.\n");elseprintf("%d\n",minn);}return 0;}
0 0
- hdu 1599 find the mincost route
- HDU 1599 find the mincost route
- hdu 1599 find the mincost route
- hdu 1599 find the mincost route
- HDU 1599 find the mincost route
- HDU 1599 find the mincost route
- hdu 1599 find the mincost route
- HDU 1599 find the mincost route
- hdu 1599 find the mincost route
- hdu 1599 find the mincost route
- HDU 1599 find the mincost route
- hdu 1599 find the mincost route
- HDU 1599 find the mincost route
- 【HDU 1599 find the mincost route】
- HDU 1599 find the mincost route
- 【HDU 1599 find the mincost route 】
- HDU 1599 find the mincost route
- HDU-1599-find the mincost route
- 静态代码块,构造代码块,构造函数的执行顺序
- word文档加密保护不能编辑问题
- C语言基础及指针⑨联合体与枚举
- GetTickCount/QueryPerformanceFrequency/QueryPerformanceCounter
- 爸爸又来纪流水账了。
- HDU 1599 find the mincost route
- LightOJ 1138 Trailing Zeroes (III)
- 杭电-2059 龟兔赛跑 (基础DP)
- 补码,负数比整数多表示一个
- LightOJ 1294
- MySQL锁机制详解及死锁处理方式
- Spark伪分布安装(依赖Hadoop)
- 【C++】fill函数,fill与memset函数的区别
- iOS app上架流程