裸的FLOYD 求最小环。

 #include <iostream>
#include <cstdio>
using namespace std;
const int inf=;
const int MAXN=;
int n,m,minc;
int map[MAXN][MAXN],dis[MAXN][MAXN]; void init(){
for(int i=;i<=n;i++){
for(int j=i;j<=n;j++)
map[i][j]=map[j][i]=dis[i][j]=dis[j][i]=inf;
map[i][i]=dis[i][i]=;
}
} void floyd(){
minc=inf;
int tmp;
for(int k=;k<=n;k++){
for(int i=;i<k;i++){
for(int j=i+;j<k;j++){
tmp=dis[i][j]+map[i][k]+map[k][j];
if(tmp<minc)
minc=tmp;
}
}
for(int i=;i<=n;i++){
for(int j=;j<=n;j++){
tmp=dis[i][k]+dis[k][j];
if(tmp<dis[i][j])
dis[i][j]=tmp;
}
}
}
} int main(){
int u,v,w;
while(scanf("%d%d",&n,&m)!=EOF){
init();
for(int i=;i<=m;i++){
scanf("%d%d%d",&u,&v,&w);
if(w<map[u][v])
map[u][v]=map[v][u]=dis[u][v]=dis[v][u]=w;
}
floyd();
if(minc==inf)
printf("It's impossible.\n");
else printf("%d\n",minc);
}
return ;
}

HDU 1599的更多相关文章

  1. hdu 1599 find the mincost route 最小环

    题目链接:HDU - 1599 杭州有N个景区,景区之间有一些双向的路来连接,现在8600想找一条旅游路线,这个路线从A点出发并且最后回到A点,假设经过的路线为V1,V2,....VK,V1,那么必须 ...

  2. hdu 1599 find the mincost route

    http://acm.hdu.edu.cn/showproblem.php?pid=1599 floyd找最小环. #include <cstdio> #include <cstri ...

  3. 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 ...

  4. 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 ...

  5. hdu 1599 find the mincost route(无向图的最小环)

    find the mincost route Time Limit: 1000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/O ...

  6. HDU 1599 find the mincost route (无向图的最小环)

    题意: 给一个带权无向图,求其至少有3个点组成的环的最小权之和. 思路: (1)DFS可以做,实现了确实可以,只是TLE了.量少的时候应该还是可以水一下的.主要思路就是,深搜过程如果当前点搜到一个点访 ...

  7. hdu 1599 find the mincost route(flyod求最小环)

    Problem Description 杭州有N个景区,景区之间有一些双向的路来连接,现在8600想找一条旅游路线,这个路线从A点出发并且最后回到A点,假设经过的路线为V1,V2,....VK,V1, ...

  8. hdu 1599 find the mincost route_最小环

    #include <iostream> #include<cstdio> using namespace std; #define N 110 #define INF 0xff ...

  9. HDU 1599 find the mincost route (无向图floyd最小环详解)

    转载请注明出处:http://blog.csdn.net/a1dark 分析:终于弄懂了floyd的原理.以前的理解一直肤浅.所以一做到floyd应用的题.就拙计了.其实floyd的本质DP.利用前K ...

  10. HDU 1599 find the mincost route (最短路 floyd)

    题目链接 Problem Description 杭州有N个景区,景区之间有一些双向的路来连接,现在8600想找一条旅游路线,这个路线从A点出发并且最后回到A点,假设经过的路线为V1,V2,....V ...

随机推荐

  1. the user must supply a jdbc connection 错误解决方法

    转自:https://blog.csdn.net/actionzh/article/details/54200451 今天在配置hibernate之后,进行添加数据测试时,运行中报出了 the use ...

  2. E20170816-mk

    deque 即双端队列.是一种具有队列和栈的性质的数据结构. revert  vi. 恢复; 重提; 回到…上; <律>归还;   n. 归属; 恢复原来信仰的人; Indicator   ...

  3. html5 拖放事件

    1.设置元素可拖拽属性:draggable true表示可拖拽. false表示不可拖拽. auto默认值,img和带href属性的a标签则表示可拖拽,其他标签表示不可被拖拽. 其他值表示不可拖拽. ...

  4. selenium3 + python - alert_is_present定位

    from selenium import webdriverfrom selenium.webdriver.support.wait import WebDriverWaitfrom selenium ...

  5. prim解决最小生成树问题

    #include <iostream> #include <algorithm> #include <stdio.h> #include <math.h> ...

  6. java反射机制学习小结

    之前一直对java的反射机制理解得很模糊,今天因为学习spring,所以花了些时间总算把它理顺了,记录一下 另外,推荐读读这篇文章,写的挺好的http://blog.csdn.net/woshixuy ...

  7. 页面中word文本框的编辑,两种方式

    大致效果图(对其中的功能可以增减): 实现方法1:调用js <link href="../../platform/js/kindeditor/themes/default/defaul ...

  8. SQLServer2008 使用BCP导入导出表数据

    --先开启cmdshell EXEC sp_configure 'show advanced options', 1 GO RECONFIGURE GO EXEC sp_configure 'xp_c ...

  9. windows phone媒体应用开发

    MediaElement 可以播放许多不同类型的音频和视频媒体. MediaElement 是一个可以在其表面显示视频的矩形区域,也可以播放音频.MediaElement 支持触控输入事件. 使用属性 ...

  10. angular2之组件通讯

    定义父组件,在父组件中以路由插座形式引入子组件,定义相关输入输出属性 可以在同一模块内部定义多个组件,将一个组件引入另一个组件中去:也可以该模块整体导出,将该模块导入到其他模块,这样此模块中的组件就能 ...