find the mincost route【无向图最小环】
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1599
接下来的M行里,每行包括3个整数a,b,c.代表a和b之间有一条通路,并且需要花费c元(c <=
100)。
impossible.".
#include<stdio.h>
#include<algorithm>
#define LL long long
#define mem(a, b) memset(a, b, sizeof(a))
using namespace std;
const LL inf = 0x3f3f3f3f;
const int MAXN = ; int n, m;
LL dis[MAXN][MAXN], map[MAXN][MAXN];//最短路径 直接路径
LL ans; void floyd()
{
ans = inf;
for(int k = ; k <= n; k ++) //枚举中点
{
for(int i = ; i < k; i ++) //起点
for(int j = i + ; j < k; j ++)//终点
ans = min(ans, map[i][k] + map[k][j] + dis[i][j]); //在dis没更新倒k之前,是没有经过k点的。所以保证了至少3个不同的点
for(int i = ; i <= n; i ++)
for(int j = ; j <= n; j ++)
dis[i][j] = min(dis[i][j], dis[i][k] + dis[k][j]);
}
if(ans != inf)
printf("%lld\n", ans);
else
printf("It's impossible.\n");
} int main()
{
while(scanf("%d%d", &n, &m) != EOF)
{
for(int i = ; i <= n; i ++)
for(int j = ; j <= n; j ++)
{
if(i == j)
dis[i][j] = map[i][j] = ;
else
dis[i][j] = map[i][j] = inf;
}
for(int i = ; i <= m; i ++)
{
int a, b;
LL c;
scanf("%d%d%lld", &a, &b, &c);
dis[a][b] = dis[b][a] = map[a][b] = map[b][a] = min(map[a][b], c);//双向边
}
floyd();
}
return ;
}
对于有向图的最小环:不同之处在于1.建图(不用说了吧 有向图的建图)2. ans = min(ans, map[i][k] + map[k][j] + dis[j][i]);
find the mincost route【无向图最小环】的更多相关文章
- 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 ...
- hdu 1599 find the mincost route(无向图的最小环)
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求无向图最小环
find the mincost route Time Limit: 1000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/O ...
- 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 P1599] find the mincost route
[hdu P1599] find the mincost route 杭州有N个景区,景区之间有一些双向的路来连接,现在8600想找一条旅游路线,这个路线从A点出发并且最后回到A点,假设经过的路线为V ...
- 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 ...
- hdu1599 find the mincost route floyd求出最小权值的环
find the mincost route Time Limit: 1000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/O ...
- POJ 1734 无向图最小环/有向图最小环
给定一张图,求图中一个至少包含三个点的环,环上的点不重复,并且环上的边的长度之和最小. 点数不超过100个 输出方案 无向图: /*Huyyt*/ #include<bits/stdc++.h& ...
随机推荐
- kafka 介绍与使用
在介绍为什么使用kafka之前,我们有必要来了解一下什么是kafka? 1. 什么是kafka? Kafka是由LinkedIn开发的一个分布式的消息系统,使用Scala编写,它以可水平扩展和高吞吐率 ...
- CF796C Bank Hacking 细节
思路十分简单,答案只有 3 种可能,但是有一些细节需要额外注意一下. code: #include <bits/stdc++.h> #define N 300002 #define set ...
- BZOJ 4241: 历史研究 ( 回 滚 )
题目: 链接:https://www.lydsy.com/JudgeOnline/problem.php?id=4241 题意:给你一个长度为n序列,m次查询,每次询问 一段区间 最大的 a[ i ...
- 「CF484E」Sign on Fence「整体二分」「线段树」
题意 给定一个长度为\(n\)的正整数序列,第\(i\)个数为\(h_i\),\(m\)个询问,每次询问\((l, r, w)\),为\([l, r]\)所有长度为\(w\)的子区间最小值的最大值.( ...
- CSPS模拟75&76
感觉自己还是太菜了... 最近考试一直想不出来正解.难受(然而蒟蒻的博客没人看也要不来小猪peiqi的图) 模拟75:血炸... 考场上推了快两个小时的T1式子,然后心态炸裂,然后我也不知道自己干了什 ...
- linux下文件传输一些方法整理.
ftp类 ftp 命令已经不推荐使用了. #基本用法 lftp sftp://[domain name] lftp sftp://theURL.org #使用不同用户名 lftp sftp://[us ...
- 使用 nginx_rtmp_module 搭建个人学习流媒体服务器
nginx 共享服务器中的视频 如果服务器处于内网或者没有公网ip,可以使用 相关软件进行打洞或转发 如: frpc https://github.com/fatedier/frp 或 holer h ...
- Golang switch语句总结
switch 语句基本结构 switch 条件表达式 { case 常量表达式1: 语句 1 case 常量表达式2: 语句 2 . . . case 常量表达式n: 语句 n default: 语句 ...
- JAVA基础知识|TCP/IP协议
虽然写代码也有一定的年头了,但是对于一些基础概念,还是很模糊.这在后来的学习过程中,带来了很大的痛苦,所以痛定思痛,决心重新学习这些概念.并把自己的理解和查询的资料做一些整合,便于以后查阅! 一.什么 ...
- centos7 - nginx配置安装phpmyadmin
原文 https://www.linuxidc.com/Linux/2017-10/147556.htm 使用Nginx搭建phpMyAdmin Nginx有什么用? Nginx可读作Engin ...