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 ...
随机推荐
- CI(CodeIgniter)框架入门教程——第二课 初始MVC
本文转载自:http://www.softeng.cn/?p=53 今天的主要内容是,使用CodeIgniter框架完整的MVC内容来做一个简单的计算器,通过这个计算器,让大家能够体会到我在第一节课中 ...
- PHP 页面跳转方法
1.php header()函数跳转 PHP的header()函数非常强大,其中在页面url跳转方面也调用简单,使用header()直接跳转到指定url页面,这时页面跳转是302重定向: $url = ...
- Tomcat5通过cardadm.xml启动项目
配置tomcat5\conf\Catalina\localhost下的 cardadm.xml ,然后在MyEclipse中,直接启动Tomcat5,不需要部署项目
- Android Intent应用
1. 显示Intent // 直接设置Content和到下一个的Actvity的名字 Intent i = new Intent(MainActivity.this, AnotherAty.class ...
- Flexbox 布局
<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8" ...
- jQuery基础--样式篇(1)
1.jQuery简介:JQuery是继prototype之后又一个优秀的Javascript库.它是轻量级的js库 ,它兼容CSS3,还兼容各种浏览器(IE 6.0+, FF 1.5+, Safari ...
- Mycat+Mysql 插入数据报错 i[Err] 1064 - partition table, insert must provide ColumnList
使用Navicat连接Mycat 8066 成功插入了分库表和全局表 1.全局表 sql如下: '); '); '); 插入成功! 2.分库表 sql如下: ', null, null, null, ...
- [转]js中的时间与毫秒数互相转换
原文地址:http://blog.sina.com.cn/s/blog_77cb836301015icr.html [1]js毫秒时间转换成日期时间 var oldTime = (new Date ...
- Linux_Shell_Bash快捷键
来自为知笔记(Wiz)
- C#-WebForm-★ 上传水印图片 ★
上传水印图片就是一个选择图片.添加水印.进行上传的过程 绘制图片需要准备: 画布 - 大小 笔 - 颜色.粗细.样式 用什么字体 要画什么(李献策lxc) 步骤: 一.引用 System.Drawin ...