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 ...
随机推荐
- 理解AngularJS生命周期:利用ng-repeat动态解析自定义directive
ng-repeat是AngularJS中一个非常重要和有意思的directive,常见的用法之一是将某种自定义directive和ng-repeat一起使用,循环地来渲染开发者所需要的组件.比如现在有 ...
- JavaScript学习笔记-简单的计时钟表
<!DOCTYPE html> <html lang="en" xmlns="http://www.w3.org/1999/xhtml"> ...
- 最短判断IE的办法
if(!!-[1,]){ return }; 无意中看到这样一行代码,经查是用来判断IE的代码,非常精简,原理如下: [1,],这是一个数组,IE和标准浏览器对这样一个数组的解析是不一样的 alert ...
- go-- 用go-mssql驱动连接sqlserver数据库
import _ "github.com/denisenkom/go-mssqldb" import ( "crypto/cipher" "crypt ...
- Day Five (beta)
站立式会议 站立式会议内容总结 331 今天:爬虫抓取豆瓣数据; 明天:数据展示在话题详情页,话题页修改 442 今天:了解聊天模块 遇到的问题:无 明天:编写聊天模块 439 今天:学习 遇到困难 ...
- Value cannot be null or empty. 参数名: contentPath
代码:<img src="@Url.Content(item.ThumbPath)" width="160" height="250" ...
- hibernate用setResultTransformer转换
当你用hibernate查出数据,但是类型不是原来的类型怎么办,新增的实体类还可以用,query.setResultTransformer(Transformers.aliasToBean(AA.cl ...
- java设计优化--代理模式
代理模式使用代理对象完成用户的请求,屏蔽用户对真实对象的访问. 代理模式的用途很多,比如因为安全原因,需要屏蔽客户端直接访问真实对象:或者在远程调用中,需要使用代理对象处理远程方法中的技术细节:或者为 ...
- 美发屋App-业余爱好
出于个人爱好, 自行设计了一款APP,由于时间有限,APP目前只做了3天,现大四,急求一份实习工作,月薪3K左右即可! 软件UI设计到编码,全部又我一人完成,所以工作量比较大 底部采用·Fragmen ...
- ( 转 ) Android自绘字体大小paint.settextsize随分辨率大小变化
1.获取当前设备的屏幕大小 DisplayMetrics displayMetrics = new DisplayMetrics(); this.getWindowManager().getDefau ...