hdu1599 find the mincost route
floyd找最小环
很好理解
#include<algorithm>
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<cstdio>
#include<string>
#include<cmath>
#include<ctime>
#include<queue>
#include<stack>
#include<map>
#include<set>
#define rre(i,r,l) for(int i=(r);i>=(l);i--)
#define re(i,l,r) for(int i=(l);i<=(r);i++)
#define Clear(a,b) memset(a,b,sizeof(a))
#define inout(x) printf("%d",(x))
#define douin(x) scanf("%lf",&x)
#define strin(x) scanf("%s",(x))
#define LLin(x) scanf("%lld",&x)
#define op operator
#define CSC main
typedef unsigned long long ULL;
typedef const int cint;
typedef long long LL;
using namespace std;
cint inf=;
void inin(int &ret)
{
ret=;int f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=;ch=getchar();}
while(ch>=''&&ch<='')ret*=,ret+=ch-'',ch=getchar();
ret=f?-ret:ret;
}
int n,m,t,dis[][],mp[][];
int floyd()
{
int ret=inf;
re(k,,n)
{
re(i,,n)if(i!=k)
re(j,,n)if(j!=k&&j!=i)
if(dis[i][j]<inf&&mp[i][k]!=inf&&mp[k][j]!=inf)
ret=min(ret,mp[i][k]+mp[k][j]+dis[i][j]);
re(i,,n)
re(j,,n)
dis[i][j]=min(dis[i][j],dis[i][k]+dis[k][j]);
}
return ret;
}
int main()
{
while(scanf("%d%d",&n,&m)!=EOF)
{
re(i,,n)re(j,,m)dis[i][j]=mp[i][j]=inf;
re(i,,m)
{
int q,w,e;inin(q),inin(w),inin(e);
dis[q][w]=dis[w][q]=mp[q][w]=mp[w][q]=min(dis[q][w],e);
}
int ans=floyd();
if(ans==inf)printf("It's impossible.\n");
else printf("%d\n",ans);
}
return ;
}
hdu1599 find the mincost route的更多相关文章
- hdu1599 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 ...
- 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 ...
- 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(无向图的最小环)
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求无向图最小环
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 ...
随机推荐
- 2018天猫双11各类目品牌成交额top10排行榜
2018天猫双11总成交额213,550,497,011元,你知道各类目品牌成交额排行吗?一起来看看吧,赶紧收藏,以后就知道要怎么买了! 相关阅读: 2018天猫双11各类目品牌成交额top10排行榜 ...
- (转)github设置添加SSH
很多朋友在用github管理项目的时候,都是直接使用https url克隆到本地,当然也有有些人使用 SSH url 克隆到本地.然而,为什么绝大多数人会使用https url克隆呢? 这是因为,使用 ...
- Oracle(1)之虚拟机下安装与简单使用
Oracle介绍与安装 简介 Oracle 数据库系统是美国 ORACLE 公司(甲骨文)提供的以分布式数据库为核心的一组软件产品,是目前最流行的客户/服务器 (CLIENT/SERVER) 或 B/ ...
- 【Linux】-NO.9.Linux.5.Nexus.1.001-【CentOS 7 Install Nexus 3.3】-
1.0.0 Summary Tittle:[Linux]-NO.9.Linux.5.Nexus.1.001-[CentOS 7 Install Nexus 3.3]- Style:Linux Seri ...
- 9个Linux系统常用监控命令
我们的系统一旦上线跑起来我们自然希望它一直相安无事,不要宕机,不要无响应,不要慢腾腾的.但是这不是打开机器电源然后放任不管就可以得到的.所以我们要监视系统的运行状况,发现问题及时处理. 对于系统和网络 ...
- 【转】JsonPath教程
https://blog.csdn.net/koflance/article/details/63262484 1. 介绍 类似于XPath在xml文档中的定位,JsonPath表达式通常是用来路径检 ...
- Linux修改SSH登录端口
Linux的默认登录端口为:22,为系统安全运维都会将端口改成其它端口. 假如我们修改的端口为:3000 1.首先要配置防火墙,允许此端口通行. /sbin/iptables -A INPUT -p ...
- cmd 修改文件或目录的执行权限
设置当前目录及子目录(/r)下所有文件(/f *)的所有者为管理员(/a) takeown /f * /a /r 我试用如下: takeown /f C:\test /a /r 设置当前目录及子目录下 ...
- UVALi 3263 That Nice Euler Circuit(几何)
That Nice Euler Circuit [题目链接]That Nice Euler Circuit [题目类型]几何 &题解: 蓝书P260 要用欧拉定理:V+F=E+2 V是顶点数; ...
- ubuntu python 安装numpy,scipy.pandas.....
http://blog.csdn.net/Yakumoyukarilan/article/details/51340358