HDU 1599 find the mincost route(floyd求无向图)
来源:互联网 发布:人文社科书籍推荐 知乎 编辑:程序博客网 时间:2024/06/05 16:36
本题为简单的floyd算法。
AC代码如下
#include<cstdio>#include<cstring>#include<iostream>#define inf 99999999#define N 105using namespace std;int e[N][N],dis[N][N];int main(){ int m,n,min,u; while(~scanf("%d%d",&n,&m)) { for(int i=1;i<=n;i++) { for(int j=i+1;j<=n;j++) { e[i][j]=e[j][i]=inf; dis[i][j]=dis[j][i]=inf; } e[i][i]=0; dis[i][i]=0; } int a,b,c; for(int i=0;i<m;i++) { scanf("%d%d%d",&a,&b,&c); if(e[a][b]>c) { e[a][b]=e[b][a]=c; dis[a][b]=dis[b][a]=c; } } min=inf; for(u=1;u<=n;u++) { for(int i=1;i<u;i++) { for(int j=i+1;j<u;j++) { if(min>dis[i][j]+e[i][u]+e[u][j]) { min=dis[i][j]+e[i][u]+e[u][j]; } } } for(int i=1;i<=n;i++) { for(int j=1;j<=n;j++) { if(dis[i][j]>dis[i][u]+dis[u][j]) { dis[i][j]=dis[i][u]+dis[u][j]; } } } } if(min<inf) cout<<min<<endl; else cout<<"It's impossible."<<endl; } return 0; }
2 0
- HDU 1599 find the mincost route(floyd求无向图)
- hdu 1599 find the mincost route(floyd求无向图的最小环)
- hdu 1599 find the mincost route(找无向图最小环)(floyd求最小环)
- HDU 1599 find the mincost route (无向图floyd最小环详解)
- hdu 1599 find the mincost route(无向图最小环,floyd)
- HDU-1599 find the mincost route (无向图最小环[Floyd])
- HDU:1599 find the mincost route(floyd+无向图最小环)
- hdu1599 find the mincost route(floyd求无向图最小环)
- hdu 1599find the mincost route(Floyd算法,最小环无向图)
- HDU 1599 find the mincost route(Floyd无向图最小环)
- hdu 1599 find the mincost route Floyd 无向图求最小环
- HDU 1599 find the mincost route Floyd求最小环
- hdu 1599 find the mincost route floyd求最小环
- HDU - 1599 find the mincost route(Floyd求最小环)
- hdu 1599 find the mincost route【floyd求最小环】
- hdu 1599 find the mincost route 求最小环floyd
- hdu 1599 find the mincost route(找无向图最小环)
- HDU 1599 find the mincost route(无向图最小环)
- java求百分比
- iOS进阶之旅-可交互式转场动画
- caffe常见问题
- C++中虚析构函数的作用
- poj1311 Octal Fractions
- HDU 1599 find the mincost route(floyd求无向图)
- MongoDB安装
- 具有交互功能的对话框
- 第一篇CSDN文章
- 利用jackson-dataformat-csv读写csv文件
- 让nodejs应用后台执行:forever
- CentOS yum 源的配置与使用
- jQuery全屏滚动插件fullPage.js
- muduo库的学习6---Buffer的基本设计