杭电1599 find the mincost route
来源:互联网 发布:求迅龙数据恢复注册机 编辑:程序博客网 时间:2024/05/17 01:16
find the mincost route
Time Limit: 1000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 3636 Accepted Submission(s): 1470
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 1598 1142 1054 1594
....弗洛伊德最小环:
#include<stdio.h>#include<string.h>#include<algorithm>#define N 1<<30-1using namespace std;int dp[1100][1100],map[1100][1100];int main(){int i,j,k,l,m,n,x,y,z;while(scanf("%d%d",&m,&n)!=EOF){//memset(dp,N,sizeof(dp));//memset(map,N,sizeof(map));for(i=0;i<=m;i++) for(j=0;j<=m;j++) { map[i][j]=N; dp[i][j]=N; } while(n--){scanf("%d%d%d",&x,&y,&z);if(map[x][y]>z)map[x][y]=map[y][x]=dp[x][y]=dp[y][x]=z;}int ans=N;for(i=1;i<=m;i++){for(j=1;j<i;j++)for(k=1;k<j;k++)ans=min(ans,dp[j][k]+map[j][i]+map[i][k]);for(j=1;j<=m;j++)for(k=1;k<=m;k++)dp[j][k]=min(dp[j][k],dp[j][i]+dp[i][k]);}if(ans==N)printf("It's impossible.\n");elseprintf("%d\n",ans);}}
0 0
- 杭电1599 find the mincost route
- 杭电-1599 find the mincost route(最小环有向图)
- find the mincost route
- find the mincost route
- find the mincost route
- find the mincost route
- find the mincost route
- find the mincost route
- 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
- Volley读取文档和图片
- 和我一起学习avalon(持续更新)
- iOS Crash闪退日志获取和上传至服务器(NSSetUncaughtExceptionHandler)
- HDU5533 Dancing Stars on Me(极角排序+判断正n边形)
- javaWeb监听器结合定时器实现定时执行任务
- 杭电1599 find the mincost route
- 使用框架的好处,hibernate缓存
- iOS学习笔记--03 UITableView相关
- SIGCHLD和waitpid的使用
- nvidia自动更新带来的问题
- Struts2常见错误-No result defined for action XXX and result input
- Android Studio 快捷键
- 一次完整的HTTP请求所经历的7个步骤
- Codeforces_4A