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, ...
随机推荐
- Codevs1922 骑士共存问题
1922 骑士共存问题 题目描述 Description 在一个n*n个方格的国际象棋棋盘上,马(骑士)可以攻击的棋盘方格如图所示.棋盘上某些方格设置了障碍,骑士不得进入. 对于给定的n*n个方格的国 ...
- Adding basic files · lcobucci/jwt@aad22ed · GitHub
Skip to content Features Business Explore Marketplace Pricing This repository Sign in or Sign up ...
- vim中NERDTREE插件的使用
一个显示目录树的插件,很不错 学习于: http://blog.csdn.net/xiongzhengxiang/article/details/7375607
- python中接受任意关键字的参数
1.*args args是非关键字参数,可以理解为形参,为了方便记忆我理解它是arguments的缩写. 2.*kwargs kwargs是键值对参数,为了方便记忆我理解它是key word argu ...
- IO流-文件操作
一.字节流读/写 文件 1.字节流 方式读取文件
- Leetcode868.Binary Gap二进制间距
给定一个正整数 N,找到并返回 N 的二进制表示中两个连续的 1 之间的最长距离. 如果没有两个连续的 1,返回 0 . 示例 1: 输入:22 输出:2 解释: 22 的二进制是 0b10110 . ...
- GNU的__builtin_popcount函数
用来计算32位的unsigned int中的1的个数, 其内部实现是根据查表法来计算的.
- typora 使用
菜单 输入+换行键,产生标题,自动更新 [toc] [TOC] 段落 按换行键建立新的一行可在行尾插入打断线,禁止向后插入 按换行键建立新的一行<br/> 标题 开头#的个数表示,空格+文 ...
- Directx11教程(50) 输出depth/stencil buffer的内容
原文:Directx11教程(50) 输出depth/stencil buffer的内容 有时候,我们需要查看depth/stencil buffer的内容,比如上一章中,我们要查看sten ...
- Auto reloading enabled
在eclipse中集成tomcat来开发时, 如果使用run as模式启动项目的话,tomcat配置Auto reloading enabled,我们修改java文件,项目会重新加载,修改的内容会生效 ...