hdu 1599 find the mincost route_最小环
#include <iostream>
#include<cstdio>
using namespace std;
#define N 110
#define INF 0xffffff
int map[N][N],n,m,dist[N][N];
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
void floyd(){
int i,j,k,ans=INF;
for(i=0;i<n;i++)
for(j=0;j<n;j++)
dist[i][j]=map[i][j];
for(k=0;k<n;k++){
for(i=0;i<k;i++)
for(j=i+1;j<k;j++)
ans=min(ans,dist[i][j]+map[i][k]+map[k][j]);
for(i=0;i<n;i++)
for(j=0;j<n;j++)
dist[i][j]=min(dist[i][j],dist[i][k]+dist[k][j]);
}
if(ans<INF)
printf("%d\n",ans);
else
printf("It's impossible.\n");
}
int main(int argc, char** argv) {
int i,j,a,b,d;
while(scanf("%d%d",&n,&m)!=EOF){
for(i=0;i<n;i++)
for(j=0;j<n;j++)
map[i][j]=INF;
for(i=0;i<m;i++){
scanf("%d%d%d",&a,&b,&d);
if(map[a-1][b-1]>d)
map[a-1][b-1]=map[b-1][a-1]=d;
}
floyd();
}
return 0;
}
hdu 1599 find the mincost route_最小环的更多相关文章
- hdu 1599 find the mincost route 最小环
题目链接:HDU - 1599 杭州有N个景区,景区之间有一些双向的路来连接,现在8600想找一条旅游路线,这个路线从A点出发并且最后回到A点,假设经过的路线为V1,V2,....VK,V1,那么必须 ...
- 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(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求无向图最小环
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
http://acm.hdu.edu.cn/showproblem.php?pid=1599 floyd找最小环. #include <cstdio> #include <cstri ...
随机推荐
- 在WPF中使用ArcGIS Engine
原文 http://blog.csdn.net/zzahkj/article/details/9102621 1.首先,新建一个WPF项目,添加引用ESRI.ArcGIS.AxControls.ESR ...
- android 中FragmentActivity中模拟返回键返回上一个Activity效果
FragmentTransaction中先加入一个Fragment,这个Fragment就是当前要显示的Fragment, 当通过事件触发显示第二个Fragment时,在加入第二个Fragment并调 ...
- 关于oracle动态视图v$datafile和v$datafile_header(转)
v$datafile是从oracle的控制文件中获得的数据文件的信息v$datafile_header是从数据文件的头部在正常运行下,两者的检查点SCN值是一致的,但当datafile出现损坏时可以用 ...
- Wap touch flispan demo
直接上代码了 仔细看看例子就会明白 简单实用 <!DOCTYPE HTML> <html> <head> <meta charset="utf-8& ...
- 使用Comparable接口的小例子
代码: public class Student implements Comparable<Student> { private int id; private String name; ...
- Android学习总结——SharedPreferences
SharePreferences存储方式,只是轻量级数据存储,xml格式的数据显示方式.简单存储步骤如下:一:获取SharePreferences对象1.SharedPreferences pref ...
- MySQL中innodb表主键设计原则
主键设计的原则:1. 一定要显式定义主键2. 采用与业务无关的单独列3. 采用自增列4. 数据类型采用int,并尽可能小,能用tinyint就不用int,能用int就不用bigint5. 将主键放在表 ...
- android onIntent 是什么东西
在Android应用程序开发的时候,从一个Activity启动另一个Activity并传递一些数据到新的Activity上非常简单,但是当您需要让后台运行的Activity回到前台并传递一些数据可能就 ...
- 实现android4.4新特性:沉浸式状态栏
先放效果图: 所谓沉浸式状态栏,就是android4.4以后新加入的ui效果,能使最顶部的状态栏自动适宜app顶部的颜色,使两者看起来更像融为一体.下面放上实现代码: requestWindowFea ...
- 动态分配内存补充 realloc
当再次在原来申请的内存基础上再加内存的时候用realloc,如果第一次分配的内存后面存储地方够用,则连着原来的申请,如果不够用,就重新找到一块够用的地方,然后把原来的复制过去 int main(int ...