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 ...
随机推荐
- jQuery.uploadify-----文件上传带进度条,支持多文件上传的插件
借鉴别人总结的uploadify:基于jquery的文件上传插件,支持ajax无刷新上传,多个文件同时上传,上传进行进度显示,控制文件上传大小,删除已上传文件. uploadify有两个版本,一个用f ...
- 关于浏览器URL中出现会话验证字符说明
服务器安装了网站安全狗,访问网站的时候会显示一串类似iissafedogccsision=7Z86v5H5z这样的会话验证信息. 安全狗官方解释 出现该字符的主要原因是用户开启了网站安全狗的CC防护的 ...
- 2-ls 显示目录内容
ls list directory contents 显示目录内容 [语法]: ls [选项] [参数] [功能介绍] ls指令用来显示目录列表,在Linux系统中有着较高的使用率.ls指令的输出信息 ...
- sqlite之聚合函数的使用
聚合函数对一组值执行计算并返回单一的值.聚合函数对一组值执行计算,并返回单个值.除了 COUNT 以外,聚合函数都会忽略空值. 聚合函数经常与 SELECT 语句的 GROUP BY 子句一起使用. ...
- linux 配置java 环境
下载jdk 并解压到 /usr/local/java/ 目录下 地址:http://www.oracle.com/technetwork/java/javase/downloads/jdk8-down ...
- react.js 公共方法 集合
截取七牛上传图片的后缀名: export function getInputKey(info){ let self = this; let obj = JSON.parse(info); let qi ...
- sql-将查询字段拼接起来
sql语句 select (a + b) as c mysql不起作用
- TODO: 图片加载框架ImageLoader的实现
1, 使用三级缓存策略 2, 使用builder模式设置ImagLoager的config
- 简单工厂VS工厂方法
前言: GOF经典的23种设计模式在IT界现已被广为流传.由于比较长时间没有用了,个人对于不同模式与模式之间的区别也渐渐模糊,故开始重温设计模式的思想.也希望更给对设计模式感兴趣的朋友些许的启发. - ...
- bzoj4381: [POI2015]Odwiedziny
这题搞了我一下午……因为一些傻X的问题…… 对于步长大于sqrt(n)的询问,我们可以直接暴力求解 然后,我们可以事先预处理出d[u][step]表示u往上跳,每次跳step步,直到跳到不能跳为止,所 ...