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& ...
随机推荐
- oracle自连接
自连接:通过表的别名,将同一张表视为多张表 select e.ename 员工姓名,b.ename 老板姓名 from emp e,emp b where e.mgr=b.empno; 注:自连接不适 ...
- js批量下载文件
关于兼容性问题: <a href="xxx.docx" target='_blank'></a> 下载文件时,这种写法是没有兼容性问题:但是下载图 ...
- 查询Linux下文件格式.
备忘 file 命令可以查一个文件的格式 readelf -h 可执行文件名. 可以查询可执行文件的详细的格式 向Windows中exeinfo 软件类
- elasticsearch _update api 更新部分字段内容
https://www.elastic.co/guide/cn/elasticsearch/guide/current/partial-updates.htmlupdate 请求最简单的一种形式是接收 ...
- 查询Oracle正在执行的sql语句及kill被锁的表
查询Oracle正在执行的sql语句及执行该语句的用户SELECT b.sid oracleID, b.username 登录Oracle用户名, b.serial#, spid 操作系统ID, pa ...
- Linux下的crontab定时执行任务简要说明
在LINUX中,周期执行的任务一般由cron这个守护进程来处理[ps -ef|grep cron].cron读取一个或多个配置文件,这些配置文件中包含了命令行及其调用时间.cron的配置文件称为“cr ...
- jdbc相比于hibernate的弊端
1.编程人员必须既懂Java语言,又懂SQL语言,才能编写数据库访问代码.(感觉用不用hibernate,SQL都要会呀) 2.程序代码中嵌入大量字符串形式的SQL语句,降低了程序代码的可读性. 3. ...
- IDEA 重复代码快速重构(抽取重复代码快捷键)
Ctrl+Alt+M 顺带一提,eclipse的快捷键是:Alt+Shift+M;
- Qt自定义委托在QTableView中绘制控件、图片、文字
自定义委托,继承于,QStyledItemDelegate类,重载Paint()函数, 1.实现在QTableView中绘制 格式字符串 2.实现在QTableView中绘制进度条 3.实现在QTab ...
- qt 创建及调用QT的 DLL
先讲一下对QT动态链接库的调用方法,主要包括: 1.显式链接DLL,调用DLL的全局函数,采用Qt的QLibrary方法 2.显示链接DLL,调用DLL中类对象.成员函数.(通过对象即可实现类成员函数 ...