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& ...
随机推荐
- 选择排序之javascript
选择排序(Selection-sort)是一种简单直观的排序算法.它的工作原理:首先在未排序序列中找到最小(大)元素,存放到排序序列的起始位置,然后,再从剩余未排序元素中继续寻找最小(大)元素,然后放 ...
- trie上构建后缀数组
例题: 往事太多,有时候忘了就忘了吧. 如果有非记不可的,就只能用点附加手段啦! 我们定义一棵往事树是一个 n 个点 n-1 条边的有向无环图,点编号为 1到 n,其中 1 号点被称为是根结点,除根结 ...
- Laravel API Errors and Exceptions: How to Return Responses
Laravel API Errors and Exceptions: How to Return Responses February 13, 2019 API-based projects are ...
- Gradle 发布 Jar 到 Archiva 时提示不能 Overwriting released artifacts is not allowed
系统提示错误信息: Received status code 409 from server: Overwriting released artifacts is not allowed. 这是在 A ...
- leetcode解题报告(9):Implement strStr()
描述 Implement strStr(). Returns the index of the first occurrence of needle in haystack, or -1 if nee ...
- 7月清北学堂培训 Day 2
今天是林永迪老师的讲授~ 继续昨日的贪心内容. 我们继续看例题: 分析样例的过河方法: 首先1和2先过河,总时间为2: 然后1回来,总时间为3: 然后5和10过河,总时间为13: 然后2回来,总时间为 ...
- 【学习笔记】OI模板整理
CSP2019前夕整理一下模板,顺便供之后使用 0. 非算法内容 0.1. 读入优化 描述: 使用getchar()实现的读入优化. 代码: inline int read() { int x=0; ...
- UVALive 4726 Average ——(斜率优化DP)
这是第一次写斜率优化DP= =.具体的做法参照周源论文<浅谈数形结合思想在信息学竞赛中的应用>.这里仅提供一下AC的代码. 有两点值得注意:1.我这个队列的front和back都是闭区间的 ...
- 【locust】使用locust + boomer实现对接口的压测
背景 很早之前,考虑单机执行能力,使用locust做过公司短信网关的压测工作,后来发现了一个golang版本的locust,性能是python版本的5到10倍以上,但是一直没有机会使用. 最近公司想做 ...
- Mysql 原理以及常见mysql 索引等
## 主键 超键 候选键 外键 (mysql数据库常见面试题) 数据库之互联网常用架构方案 数据库之互联网常用分库分表方案 分布式事务一致性解决方案 MySQL Explain详解 ## 数据库事务的 ...