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): 2530 Accepted Submission(s):
1006
1000),代表景区的个数和道路的条数。
接下来的M行里,每行包括3个整数a,b,c.代表a和b之间有一条通路,并且需要花费c元(c <=
100)。
impossible.".
for(int i=0;i<k;++i)
for(int j=0;j<i;++j)
mincircle = min(mincircle,Dist[i][j]+Graph[j][k]+Graph[k][i]);
for(int j=0;j<i;++j){
#include <iostream>
#include <cstdio>
using namespace std; int n,node[][],map[][],Min;
const int INF=; int floyd()
{
for (int i=; i<=n; i++)
for (int j=; j<=n; j++)
{
node[i][j]=map[i][j];
}
Min=INF;
for (int k=; k<=n; k++)
{
for (int i=; i<=k; i++)
for (int j=; j<i; j++)
{
if (Min>node[i][j]+map[j][k]+map[k][i])
Min=node[i][j]+map[j][k]+map[k][i];
//cout<<Min<<endl;
}
for (int i=; i<=n; i++)
for (int j=; j<=n; j++)
{
if (node[i][j]>node[i][k]+node[k][j])
node[i][j]=node[i][k]+node[k][j];
}
}
return Min;
} int main ()
{
int m;
while (~scanf("%d%d",&n,&m))
{
for (int i=; i<=n; i++)
{
for (int j=; j<=n; j++)
map[i][j]=node[i][j]=INF;
}
while (m--)
{
int a,b,c;
scanf("%d%d%d",&a,&b,&c);
if (map[a][b]>c)
map[a][b]=map[b][a]=c;
}
floyd();
if (Min==INF)
printf ("It's impossible.\n");
else
printf ("%d\n",Min);
}
return ;
}
hdu 1599 find the mincost route (最小环与floyd算法)的更多相关文章
- HDU 1599 find the mincost route (无向图floyd最小环详解)
转载请注明出处:http://blog.csdn.net/a1dark 分析:终于弄懂了floyd的原理.以前的理解一直肤浅.所以一做到floyd应用的题.就拙计了.其实floyd的本质DP.利用前K ...
- 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 (最短路 floyd)
题目链接 Problem Description 杭州有N个景区,景区之间有一些双向的路来连接,现在8600想找一条旅游路线,这个路线从A点出发并且最后回到A点,假设经过的路线为V1,V2,....V ...
- 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 (无向图的最小环)
题意: 给一个带权无向图,求其至少有3个点组成的环的最小权之和. 思路: (1)DFS可以做,实现了确实可以,只是TLE了.量少的时候应该还是可以水一下的.主要思路就是,深搜过程如果当前点搜到一个点访 ...
- hdu 1599 find the mincost route(flyod求最小环)
Problem Description 杭州有N个景区,景区之间有一些双向的路来连接,现在8600想找一条旅游路线,这个路线从A点出发并且最后回到A点,假设经过的路线为V1,V2,....VK,V1, ...
随机推荐
- 【Linux】- rm命令
Linux rm命令用于删除一个文件或者目录. 语法 rm [options] name... 参数: -i 删除前逐一询问确认. -f 即使原档案属性设为唯读,亦直接删除,无需逐一确认. -r 将目 ...
- [C/C++] 原码、反码、补码问题
正确答案:D 解析: C语言中变量以补码形式存放在内存中,正数的补码与原码相同,负数求补码方式为(符号位不变,其余各位取反,最后末尾加1): 32位机器:int 32位,short 16位. x = ...
- ajax 请求 后台返回的文件流
download(url) { var xhr = new XMLHttpRequest(); xhr.open('GET', url, true); // 也可以使用POST方式,根据接口 xhr. ...
- SpringBoot事件监听
代码演示: package com.boot.event.eventdemo; import org.springframework.boot.SpringApplication; import or ...
- [六省联考2017]分手是祝愿 期望DP
表示每次看见期望的题就很懵逼... 但是这题感觉还是值得一做,有可借鉴之处 要是下面这段文字格式不一样的话(虽然好像的确不一样,我也不知道为什么,是直接从代码里面复制出来的,因为我一般都是习惯在代码里 ...
- linux查找文件目录及mysql卸载
我们要卸载 mysql但是不知道其安装在哪里了,可以用 where +关键词 的方式查找,如上图 输入 whereis mysql 后,下面显示出了4个包含mysql的位置. ..... 查看安装m ...
- ringbuffer
http://blog.csdn.net/xiaolang85/article/details/38419163
- POJ 3107 树形dp
Godfather Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 6812 Accepted: 2390 Descrip ...
- 轮廓问题/Outline Problem
--------------------------------------------------- //已发布改进后的轮廓问题算法:http://www.cnblogs.com/andyzeng/ ...
- android Handler post sendMessage
Handler 为Android操作系统中的线程通信工具,包为android.os.Handler. 与Handler绑定的有两个队列,一个为消息队列,另一个为线程队列.Handler可以通过这两个队 ...