hdu 1599 find the mincost route(无向图的最小环)
find the mincost route
Time Limit: 1000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 3885 Accepted Submission(s):
1559
1000),代表景区的个数和道路的条数。
接下来的M行里,每行包括3个整数a,b,c.代表a和b之间有一条通路,并且需要花费c元(c <=
100)。
impossible.".
#include <iostream>
#include <cstdio>
#include <cstring>
#define M 1005
#define MAX 1000000
using namespace std;
int map[M][M],dis[M][M];
int n; void floyd()
{
int i,j,k;
int ans=MAX;
for(k=; k<=n; k++)
{
for(i=; i<k; i++)
for(j=i+; j<k; j++)
if(ans>map[i][k]+map[k][j]+dis[j][i]) //注意这里的写法
ans=map[i][k]+map[k][j]+dis[j][i];
for(i=; i<=n; i++)
for(j=; j<=n; j++)
if(dis[i][j]>dis[i][k]+dis[k][j])
dis[i][j]=dis[i][k]+dis[k][j];
}
if(ans<MAX)
printf("%d\n",ans);
else
printf("It's impossible.\n");
} int main()
{
int m,i,j;
while(~scanf("%d%d",&n,&m))
{
for(i=; i<=n; i++)
for(j=; j<=n; j++)
{
if(i==j) map[i][j]=dis[i][j]=;
else map[i][j]=dis[i][j]=MAX;
}
int a,b,c;
while(m--)
{
scanf("%d%d%d",&a,&b,&c);
if(map[a][b]>c)
map[a][b]=map[b][a]=dis[a][b]=dis[b][a]=c;
}
floyd();
}
return ;
}
hdu 1599 find the mincost route(无向图的最小环)的更多相关文章
- 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 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 最小环
题目链接:HDU - 1599 杭州有N个景区,景区之间有一些双向的路来连接,现在8600想找一条旅游路线,这个路线从A点出发并且最后回到A点,假设经过的路线为V1,V2,....VK,V1,那么必须 ...
- 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 1599 find the mincost route (无向图的最小环)
题意: 给一个带权无向图,求其至少有3个点组成的环的最小权之和. 思路: (1)DFS可以做,实现了确实可以,只是TLE了.量少的时候应该还是可以水一下的.主要思路就是,深搜过程如果当前点搜到一个点访 ...
- HDU 1599 find the mincost route (无向图floyd最小环详解)
转载请注明出处:http://blog.csdn.net/a1dark 分析:终于弄懂了floyd的原理.以前的理解一直肤浅.所以一做到floyd应用的题.就拙计了.其实floyd的本质DP.利用前K ...
- 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(flyod求最小环)
Problem Description 杭州有N个景区,景区之间有一些双向的路来连接,现在8600想找一条旅游路线,这个路线从A点出发并且最后回到A点,假设经过的路线为V1,V2,....VK,V1, ...
随机推荐
- 使用log4j打印日志
在项目中我们必不可少需要打印日志,通过日志我们可以查看系统的运行状态是否正常,当程序出现异常的时候,我们也可以通过查看日志来定位问题的位置,给程序员的工作带来了极大的便利. 以下这边博客的内容是我从一 ...
- jquery tooltip.js
1.引用关联的js脚本 <script type="text/javascript" src="script/jquery-1.3.2.min.js"&g ...
- Faster RCNN算法训练代码解析(3)
四个层的forward函数分析: RoIDataLayer:读数据,随机打乱等 AnchorTargetLayer:输出所有anchors(这里分析这个) ProposalLayer:用产生的anch ...
- toString方法和valueof()方法的区别
JavaScript引用类型之Array数组的toString()和valueof()方法的区别 一.转换方法 1.在JavaScript中几乎所有对象都具有toLocaleString().to ...
- ORACLE 使用笔记
ORACLE TRUNC()函数 TRUNC():类似截取函数,按指定的格式截取输入的数据. 1.[trunc(for dates)]TRUNC()函数处理日期 语法格式:TRUNC(date[,fm ...
- Direct2D 第3篇 绘制文字
原文:Direct2D 第3篇 绘制文字 #include <windows.h> #include <d2d1.h> #include <d2d1helper.h> ...
- jsp之jstl(展示所有商品、重写登录案例)
jsp之jstl jstl: jsp标准的标签库语言,apache的,是用来替代java脚本 使用步骤: 1.导入jar包 (jstl.jar和standard.jar) 2.在页面上导入标签库 &l ...
- Javascript一些要点记录
1. == 比较,它会自动转换数据类型再比较 === 比较,它不会自动转换数据类型,如果数据类型不一致,返回false 大部分时候应该使用===来比较2. 使用'use strict'来强制通过var ...
- var与let循环中经典问题
循环1: 下面代码运行结果是输出10 <script> var a =[]; for(var i = 0;i<10;i++){ a[i] = function(){ consol ...
- jquery的innerWidth 和 innerHeight的使用
innerWidth This method returns the width of the element, including left and right padding, in pixels ...