HDU 1599 find the mincost route (Floyd 最小环)
2015-02-10 21:23
405 查看
find the mincost route
Time Limit: 1000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 2802 Accepted Submission(s): 1116
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)。
Output
对于每个测试实例,如果能找到这样一条路线的话,输出花费的最小值。如果找不到的话,输出"It's impossible.".
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.
Author
8600
Source
HDU 2007-Spring Programming Contest -
Warm Up (1)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1599
题目大意:求最小环
题目分析:求最小环的方法,参照本博客POJ 1734那篇,这里不需要记录路径,直接拍个模板
#include <cstdio> #include <cstring> int const INF = 0xfffffff; int const MAX = 105; int d[MAX][MAX], map[MAX][MAX]; int n, m, mi; void init() { mi = INF; for(int i = 1; i <= n; i++) for(int j = 1; j <= n; j++) map[i][j] = d[i][j] = INF; } void Floyd() { for(int k = 1; k <= n; k++) { for(int i = 1; i < k; i++) for(int j = 1; j < i; j++) if(d[i][j] + map[i][k] + map[k][j] < mi) mi = d[i][j] + map[i][k] + map[k][j]; for(int i = 1; i <= n; i++) for(int j = 1; j <= n; j++) if(d[i][j] > d[i][k] + d[k][j]) d[i][j] = d[i][k] + d[k][j]; } } int main() { int u, v, w; while(scanf("%d %d", &n, &m) != EOF) { init(); for(int i = 0; i < m; i++) { scanf("%d %d %d", &u, &v, &w); if(map[u][v] > w) { map[u][v] = map[v][u] = w; d[u][v] = d[v][u] = w; } } Floyd(); if(mi == INF) printf("It's impossible.\n"); else printf("%d\n", mi); } }
相关文章推荐
- HDU 1599 find the mincost route(Floyd最小环)
- HDU 1599 find the mincost route(Floyd判最小环)
- hdu 1599 find the mincost route(floyd求无向图的最小环)
- hdu 1599 find the mincost route(floyd 最小环)
- HDU 1599 find the mincost route【floyd 最小环】
- hdu 1599 find the mincost route(无向图最小环,floyd)
- hdu 1599 find the mincost route Floyd 无向图求最小环
- hdu 1599 find the mincost route (最小环与floyd算法)
- HDOJ 题目1599 find the mincost route(Floyd最小环)
- HDU 1599 find the mincost route (无向图的最小环)
- hdu 1599 find the mincost route (最小环与floyd算法)
- 【HDU 1599】find the mincost route 【最小环】
- hdu 1599 find the mincost route(找无向图最小环)(floyd求最小环)
- HDU1599 find the mincost route(floyd求最小环)
- HDU 1599 find the mincost route(floyd改/找最小环)
- HDU 1599 find the mincost route(floyd求无向图)
- HDU 1599 find the mincost route(Floyd无向图最小环)
- hdu 1599 find the mincost route【floyd求最小环】
- hdu 1599 find the mincost route(最小环)
- hdu 1599 find the mincost route(无向图的最小环)