hdu 1599 find the mincost route
http://acm.hdu.edu.cn/showproblem.php?pid=1599
floyd找最小环。
#include <cstdio>
#include <cstring>
#include <algorithm>
#define maxn 200
using namespace std;
const int inf=<<; int g[maxn][maxn],dis[maxn][maxn];
int n,m,a,b,c; int main()
{
while(scanf("%d%d",&n,&m)!=EOF)
{
for(int i=; i<=n; i++)
{
for(int j=; j<=n; j++)
{
g[i][j]=inf;
}
}
for(int i=; i<m; i++)
{
scanf("%d%d%d",&a,&b,&c);
g[a][b]=g[b][a]=min(g[a][b],c);
}
for(int i=; i<=n; i++)
{
for(int j=; j<=n; j++)
{
dis[i][j]=g[i][j];
}
}
int min1=inf;
for(int k=; k<=n; k++)
{
for(int i=; i<k; i++)
{
for(int j=; j<i; j++)
{
min1=min(min1,dis[i][j]+g[i][k]+g[k][j]);
}
}
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(min1==inf)
printf("It's impossible.\n");
else
printf("%d\n",min1);
}
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(无向图的最小环)
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,那么必须 ...
- 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 (无向图的最小环)
题意: 给一个带权无向图,求其至少有3个点组成的环的最小权之和. 思路: (1)DFS可以做,实现了确实可以,只是TLE了.量少的时候应该还是可以水一下的.主要思路就是,深搜过程如果当前点搜到一个点访 ...
- hdu 1599 find the mincost route(flyod求最小环)
Problem Description 杭州有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 ...
随机推荐
- 这样就算会了PHP么?-2
学些关于函数FUNCTION方面的东东.. 感觉和PYTHON的APLLY功能差不多.. <?php function come(){ echo "来啦<p>"; ...
- 哪些产品不用开发原生APP,微信公众号就够了?
最近一阶段H5技术被推到高峰,很多人认为借助H5就能利用微信公众号取代APP原生应用了,而事实是怎么样的?这里我从产品层做一个客观分析. 一,原生APP总体趋势 要谈APP是否会被微信取代,那么必须回 ...
- java cannot find the tag library descriptor for "http://java.sun.com/jsp/jstl/core"
出现java cannot find the tag library descriptor for "http://java.sun.com/jsp/jstl/core" 主要的愿 ...
- "V租房"搭建微信租房平台,让租房人发起求租需求并接收合适房源回复,提高租房效率 | 36氪
"V租房"搭建微信租房平台,让租房人发起求租需求并接收合适房源回复,提高租房效率 | 36氪 "V租房"搭建微信租房平台,让租房人发起求租需求并接收合适房源回复 ...
- C# 使用Sqlite 如何返回统计行数
Visual 2010 with Sqlite 需要这样Query 数据: select count(*) from tblOrder where OrderStartTime >= '2013 ...
- 在Spring aop中的propagation的7种配置的意思
<tx:method name="find*" read-only="true" propagation ="NOT_SUPPORTED&quo ...
- hdu 5012 Dice
Problem Description There are 2 special dices on the table. On each face of the dice, a distinct num ...
- ASIHttpRequest:创建队列、下载请求、断点续传、解压缩
ps:本文转载自网络:http://ryan.easymorse.com/?p=12 感谢作者 工程完整代码下载地址:RequestTestDownload1 可完成: 下载指定链接的zip压缩文件 ...
- VC6.0建立控制台程序实现PDA应用
作者:iamlaosong 由于须要,又写起了文本界面的程序,以便PDA通过telnet连上运行. 假设是Linuxserver的话.这是非常easy的事,但是用户server是windows ser ...
- Git实现从本地加入项目到远程仓库
Git是如今最流行的版本号控制系统之中的一个了,今天也试试了.成功了上传了远程仓库,接下来看看我是怎么做的. 1.首先,要有git的账号.点击查看怎么注冊? 2.注冊成功之后.登陆GitHub.然后, ...