find the mincost route(floyd变形 无向图最小环)
Time Limit: 1000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1630 Accepted Submission(s): 664
接下来的M行里,每行包括3个整数a,b,c.代表a和b之间有一条通路,并且需要花费c元(c <= 100)。
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std; const int INF = ;
const int N = ;
int n,m;
int map[N][N],dis[N][N];
int ans; void floyd()
{
int i,j,k;
ans = INF;
for(k = ; k <= n; k++)
{
for(i = ; i < k; i++)
{
for(j = i+; j < k; j++)
{
ans = min(ans,dis[i][j]+map[j][k]+map[k][i]);
}
} for(i = ; i <= n; i++)
{
for(j = ; j <= n; j++)
{
if(dis[i][j] > (dis[i][k]+dis[k][j]))
dis[i][j] = dis[i][k]+dis[k][j];
}
}
}
}
int main()
{
while(~scanf("%d %d",&n,&m))
{
for(int i = ; i <= n; i++)
{
for(int j = ; j <= n; j++)
{
map[i][j] = INF;
dis[i][j] = INF;
}
} while(m--)
{
int u,v,w;
scanf("%d %d %d",&u,&v,&w);
if(map[u][v] > w)
{
map[u][v] = map[v][u] = w;
dis[u][v] = dis[v][u] = w;
}
}
floyd();
if(ans < INF)
printf("%d\n",ans);
else printf("It's impossible.\n"); }
return ;
}
find the mincost route(floyd变形 无向图最小环)的更多相关文章
- hdu 1599 find the mincost route floyd求无向图最小环
find the mincost route Time Limit: 1000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/O ...
- hdu1599 find the mincost route floyd求出最小权值的环
find the mincost route Time Limit: 1000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/O ...
- HD1599 find the mincost route(floyd + 最小环)
题目链接 题意:求最小环 第一反应时floyd判断,但是涉及到最少3个点,然后就不会了,又想的是 双联通分量,这个不知道为什么不对. Floyd 判断 最小环 #include <iostrea ...
- FZU 2090 旅行社的烦恼 floyd 求无向图最小环
题目链接:旅行社的烦恼 题意是求无向图的最小环,如果有的话,输出个数,并且输出权值. 刚刚补了一发floyd 动态规划原理,用了滑动数组的思想.所以,这个题就是floyd思想的变形.在k从1到n的过程 ...
- poj1734 Sightseeing trip(Floyd求无向图最小环)
#include <iostream> #include <cstring> #include <cstdio> #include <algorithm> ...
- hdu 1599 find the mincost route(flyod求最小环)
Problem Description 杭州有N个景区,景区之间有一些双向的路来连接,现在8600想找一条旅游路线,这个路线从A点出发并且最后回到A点,假设经过的路线为V1,V2,....VK,V1, ...
- HDU 1599 find the mincost route(floyd求最小环 无向图)
传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1599 find the mincost route Time Limit: 1000/2000 MS ...
- hdu 1599 find the mincost route (最小环与floyd算法)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1599 find the mincost route Time Limit: 1000/2000 MS ...
- hdu 1599 find the mincost route(无向图的最小环)
find the mincost route Time Limit: 1000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/O ...
随机推荐
- spring aop 如何切面到mvc 的controller--转载
原文:http://yjian84.iteye.com/blog/1920787 网上搜罗半天,不知道什么原因,看了源码,好像他们说的controller 是不受代理的,也对哈,不知道怎么办,于是在h ...
- 使用strut2要注意的问题
- Couchbase用的端口
文档首页: http://www.couchbase.com/documentation http://docs.couchbase.com/couchbase-manual-2.2/#prepara ...
- sql - 以半月,每月 分组
按半月:完整代码: SELECT siteNumber [站点], CONVERT(VARCHAR(7),day,120)+'-'+ case when day(day) between 1 and ...
- 灵活运用绑定变量---declare匿名块使用绑定变量
declare type cur01 is ref cursor; v_cur cur01; v_match123 varchar2(2000); v ...
- RAC配置、安装
RAC 配置及安装 2012年12月30日 星期日 21:49 ******************************************************************* ...
- vs2010安装路径解决不能修改的方法
环境:win7 64位 解决:网上说需要卸载以下4项 Microsoft Visual Studio Tools for Applications 2.0 - ENU Microsoft Visual ...
- corejava-chap01
<java是什么:>Programming language 程序语言Development environment 开发环境Application environment 应用环境Dep ...
- Linux数据写操作改进
Linux的IO操作中数据的写函数int nwrite = write(int fd,void* buf ,int len)表示向fd文件描述符写入len个字节长度的数据报文,但是这并不能保证真正向内 ...
- 赋值,copy和deepcopy
python的复制,拷贝,和深拷贝. >>> a=[23,3]>>> b=a>>> b.append(234)>>> a[23, ...