HD1599 find the mincost route(floyd + 最小环)
题意:求最小环
第一反应时floyd判断,但是涉及到最少3个点,然后就不会了,又想的是 双联通分量,这个不知道为什么不对。
Floyd 判断 最小环
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
const int INF = 0x3f3f3f3f;
const int Max = + ;
int g[Max][Max], dist[Max][Max];
//dist【i】【j】保存i到j的最短路经,然后i -> j -> k 就可以枚举k, dist[i][j] + g[i][k] + g[j][k]就是一个环的权值
int mincost;
void Floyed(int n)
{
mincost = INF;
for (int k = ; k <= n; k++)
{
for (int i = ; i < k; i++)
{
for (int j = i + ; j < k; j++)
{
if (dist[i][j] != INF && g[i][k] != INF && g[k][j] != INF)
{
int temp = dist[i][j] + g[i][k] + g[k][j]; // 原先这里直接相加,一直没找到错误,爆精度
if (temp < mincost)
mincost = temp;
}
}
}
for (int i = ; i <= n; i++)
{
for (int j = ; j <= n; j++)
{
if (dist[i][k] != INF && dist[k][j] != INF)
dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
}
}
}
}
int main()
{
int n, m;
while (scanf("%d%d", &n, &m) != EOF)
{
for (int i = ; i < Max; i++)
for (int j = ; j < Max; j++)
{
g[i][j] = INF;
dist[i][j] = INF;
}
int a, b, c;
for (int i = ; i <= m; i++)
{
scanf("%d%d%d", &a, &b, &c);
if (g[a][b] > c)
g[a][b] = g[b][a] = dist[a][b] = dist[b][a] = c;
}
Floyed(n);
if (mincost >= INF)
printf("It's impossible.\n");
else
printf("%d\n", mincost); }
return ;
}
HD1599 find the mincost route(floyd + 最小环)的更多相关文章
- find the mincost route(最小环,最短路,floyd)
find the mincost route Time Limit: 1000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/O ...
- 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 ...
- find the mincost route(floyd变形 无向图最小环)
Time Limit: 1000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission( ...
- hdoj 1599 find the mincost route【floyd+最小环】
find the mincost route Time Limit: 1000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/O ...
- 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 ...
- find the mincost route【无向图最小环】
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1599 Problem Description 杭州有N个景区,景区之间有一些双向的路来连接,现在860 ...
随机推荐
- hystrix-turbine 监控的使用
1. 概述 Demo地址:http://git.oschina.net/zhou666/spring-cloud-7simple/tree/master/cloud-hystrix-turbine ...
- windows部署React-Native的开发环境实践(技术细节)
前情摘要 众所周知,有人说.net可以用Xamrian,呵呵,不习惯收费的好么?搞.Net的人设置一次java的环境变量,可能都觉得实在太麻烦了,可能是因为这些年微软确实把我们给带坏了,所有东西一键安 ...
- php缓存技术(减少数据库服务器压力)
静态缓存(保存在磁盘上的静态文件,用PHP生成数据放入静态文件中) a) php操作缓存 i. 生成缓存 ii. 获取缓存 iii. 删除缓存 判断目录是否存在:is_dir() dirname ...
- ModernUI教程:主题资源引用
已经完成的主题资源列表 提示:请关注Modern UI的开发工作,资源文件可能在演进版本中新增和删除. 资源列表可以去访问原文,原文可复制,该表未改动原文. 查看目录
- 创建多个Oracle数据库及相应的实例
转 http://blog.csdn.net/luiseradl/article/details/6972217 对于使用过SQL Server数据库的用户可以会对Oracle中的数据库的实例的概念理 ...
- 记一次在Eclipse中用Axis生成webservice服务端的过程中出现的问题
问题一. Unable to find config file. Creating new servlet engine config file: /WEB-INF/server-config.ws ...
- 软件工程(FZU2015)学生博客列表(最终版)
FZU:福州大学软件工程 张老师的博客:http://www.cnblogs.com/easteast/ 经过前两周选课,最后正式选上课程的所有学生博客如下: 序号 学号后3位 博客 1 629 li ...
- 1031MVCC和事务浅析
转自 http://blog.csdn.net/sofia1217/article/details/50778906 关于MVCC浅析,有些难度http://xuebinbin212.blog.163 ...
- android textview改变部分文字的颜色和string.xml中文字的替换(转)
转 :http://blog.csdn.net/ljz2009y/article/details/23878669 一:TextView组件改变部分文字的颜色: TextView textView ...
- editplus-使用正则表达式替换每行首字母和尾字母
打开EditPlus,输入多行数据,快捷键ctrl+h 打开替换窗口,选择“正则表达式”替换 行首批量添加 查找"^" 替换为“我是行首aaa” 行尾批量添加 查找&quo ...