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 (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 7047 Accepted Submission(s): 2736
接下来的M行里,每行包括3个整数a,b,c.代表a和b之间有一条通路,并且需要花费c元(c <= 100)。
1 2 1
2 3 1
1 3 1
3 3
1 2 1
1 2 3
2 3 1
It's impossible.
#include <iostream>
#include <cstdio>
#include<stdio.h>
#include<algorithm>
#include<cstring>
#include<math.h>
#include<memory>
#include<queue>
using namespace std;
typedef long long LL;
#define max_v 105
#define INF 0x7ffffff
int G[max_v][max_v];
int dis[max_v][max_v];
int m,n,minc;
void floyd()
{
minc=INF;
for(int k=;k<=n;k++)//前K-1个点的情况递推前K个点的情况
{
for(int i=;i<=k;i++)
{
for(int j=i+;j<=k;j++)//i j两个点必然不同
{
minc=min(minc,dis[i][j]+G[i][k]+G[k][j]);//K为环的最大点、无向图三点成环(从k点出发,回到k点)
}
}
for(int i=;i<=n;i++)//floyd算法求任意两点的最短路、包含前K-1个点
{
for(int j=;j<=n;j++)
{
if(dis[i][j]>dis[i][k]+dis[k][j])
{
dis[i][j]=dis[i][k]+dis[k][j];
}
}
}
}
}
void init()//初始化必须全部都为无穷大、因为自身不能成环
{
for(int i=;i<max_v;i++)
{
for(int j=;j<max_v;j++)
{
G[i][j]=INF;
dis[i][j]=INF;
}
}
}
int main()
{
while(~scanf("%d %d",&n,&m))
{
init();
int s,e,v;
for(int i=;i<=m;i++)
{
scanf("%d %d %d",&s,&e,&v);
if(v<G[s][e])//重边
{
G[s][e]=G[e][s]=v;
dis[s][e]=dis[e][s]=v;
}
}
floyd();
if(minc<INF)
printf("%d\n",minc);
else
printf("It's impossible.\n");
}
return ;
}
HDU 1599 find the mincost route(floyd求最小环 无向图)的更多相关文章
- 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 ...
- 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(flyod求最小环)
Problem Description 杭州有N个景区,景区之间有一些双向的路来连接,现在8600想找一条旅游路线,这个路线从A点出发并且最后回到A点,假设经过的路线为V1,V2,....VK,V1, ...
- hdu1599 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(无向图的最小环)
find the mincost route Time Limit: 1000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/O ...
- hdu 1599 find the mincost route
http://acm.hdu.edu.cn/showproblem.php?pid=1599 floyd找最小环. #include <cstdio> #include <cstri ...
- hdu 1599 find the mincost route 最小环
题目链接:HDU - 1599 杭州有N个景区,景区之间有一些双向的路来连接,现在8600想找一条旅游路线,这个路线从A点出发并且最后回到A点,假设经过的路线为V1,V2,....VK,V1,那么必须 ...
- HDU 1599 find the mincost route (无向图floyd最小环详解)
转载请注明出处:http://blog.csdn.net/a1dark 分析:终于弄懂了floyd的原理.以前的理解一直肤浅.所以一做到floyd应用的题.就拙计了.其实floyd的本质DP.利用前K ...
- HDU 1599 find the mincost route (最短路 floyd)
题目链接 Problem Description 杭州有N个景区,景区之间有一些双向的路来连接,现在8600想找一条旅游路线,这个路线从A点出发并且最后回到A点,假设经过的路线为V1,V2,....V ...
随机推荐
- Java基础小结
JavaSE基础 本文为作者在学习和笔试题中遇到的小知识点总结,做以总结和备用. jdk的安装和配置环境变量 (1)以win10为例,右键此电脑,选择属性,进去系统设置,选择高级系统设置,进入环境变量 ...
- webpack-bundle.js原理
bundle.js 源码 //a.js import { log } from './b.js' log('hello') //b.js export const log = function (m) ...
- DOM基础操作(一)
DOM的基本操作有四种,我们会逐一给大家进行展示 增加操作 1.创建元素节点 createElement 我们可以通过document.createElement(‘div’);这个方法来创建一个元素 ...
- bzoj1201: [HNOI2005]数三角形----递推+bitset
-by bzoj http://www.lydsy.com/JudgeOnline/problem.php?id=1201 枚举所有交点,统计每个以每个点为顶点的正三角和和以每个点为左端点的反三角 ...
- Tomcat学习总结(一):目录简介
一:下载地址和目录结构说明. Tomcat官方站点:http://jakarta.apache.org 下载Tomcat安装程序包:http://tomcat.apache.org/
- MySQL与PHP的连接教程步骤(图文)
本篇文章我们介绍一下PHP与MySQL的整合,既然是与MySQL整合,那么我们首先肯定是要安装MySQL.下面我们就介绍下MySQL的安装方法. 第一步,下载MySQL.下载PHP可以去PHP中文网下 ...
- XAMPP添加二级域名
1.在hosts中添加域名 2.点击config选择httpd.conf,去掉Include前面的#号 3.取消NameVirtualHost前面的##,在页面底端添加二级域名 4.重启xampp
- python模拟登陆豆瓣——简单方法
学爬虫有一段时间了,前面没有总结又重装了系统,导致之前的代码和思考都没了..所以还是要及时整理总结备份.下面记录我模拟登陆豆瓣的方法,方法一登上了豆瓣,方法二重定向到了豆瓣中“我的喜欢”列表,获取了第 ...
- 微信小程序一个页面多个按钮分享怎么处理
首先呢,第一步先看api文档: 组件:button https://developers.weixin.qq.com/miniprogram/dev/component/button.html 框架- ...
- 初识WCF1
参照: http://blog.csdn.net/songyefei/article/details/7363296 第一篇 Hello WCF WCF(Windows Communication F ...