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& ...
随机推荐
- SIGCHLD函数
SIGCHLD的产生条件 子进程终止时 子进程接收到SIGSTOP信号停止时 子进程处在停止态,接受到SIGCONT后唤醒时 借助SIGCHLD信号回收子进程 子进程结束运行,其父进程会收到SIGCH ...
- JavaWeb_(Spring框架)用户登陆Spring整合到Servlet中
一.使用servlet技术开发用户登陆功能 在MySQL中准备一个user表,表中增加一条假数据 使用Servlet实现用户登陆的功能 用户登陆的<from>表单 <form id= ...
- Hdu5178
Hdu5178 题意: 题目给你N个点,问有多少对点的长度小于K . 解法: 首先将所给的坐标从大到小排序,则此题转化为:对排序后的新数列,对每个左边的\(x_a\)找到它右边最远的 $ x_b $ ...
- Hive 参数
hive.exec.max.created.files •说明:所有hive运行的map与reduce任务可以产生的文件的和 •默认值:100000 hive.exec.dynamic.partit ...
- Apache Flink - 配置依赖,连接器,库
每个Flink程序都依赖于一组Flink库. 1.Flink核心和应用程序依赖项 Flink本身由一组类和运行需要的依赖组成.所有类和依赖的组合形成了Flink运行时的核心,并且当一个Flink程序运 ...
- 你真的会用go语言写单例模式吗?
最近在学习Golang,想着可以就以前的知识做一些串通,加上了解到go语言也是面向对象编程语言之后.在最近的开发过程中,我碰到一个问题,要用go语言实现单例模式.本着“天下知识,同根同源”(我瞎掰的~ ...
- go结构体的方法和普通函数
package main import ( "fmt" "math" ) type vertex struct { X, Y float64 } //值接收者是 ...
- 创建createElement
let oDiv = { tag:'div', props:{ id:'box' } }: let oP = createElement('p',{'class':'list'},['周一']) ...
- nltk data 离线安装
运行程序时发现如下错误: 在命令行下载速度太慢,因此需要离线安装: 按照:http://www.nltk.org/data.html 中manual installation的方法, 将包下载好后解压 ...
- eclipse CDT Error: Program "g++" not found in PATH
右击project explore ->properties- >c/c++ build->environment , 设置 mingw_home 路径