[hdu1599]find the mincost route
来源:互联网 发布:盖世豪侠 知乎 编辑:程序博客网 时间:2024/04/28 14:37
一句话题意:求无向图的最小环的长度。
emm,这应该算是模板题或者叫floyd的经典应用吧。
#include<bits/stdc++.h>#define inf 100000000using namespace std;int n,m,x,y,z;int f[105][105],g[105][105];inline void floyd(){ int mini=inf; for(int k=1;k<=n;k++) { for(int i=1;i<k;i++) for(int j=1;j<i;j++) mini=min(mini,f[i][j]+g[j][k]+g[k][i]); for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) f[i][j]=min(f[i][j],f[i][k]+f[k][j]); } if(mini!=inf)printf("%d\n",mini); else printf("It's impossible.\n"); }int main(){ freopen("in.txt","r",stdin); while(scanf("%d%d",&n,&m)!=EOF) { for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) f[i][j]=g[i][j]=inf; for(int i=1;i<=m;i++) { scanf("%d%d%d",&x,&y,&z); f[x][y]=min(f[x][y],z); f[y][x]=f[x][y]; g[x][y]=g[y][x]=f[x][y]; } floyd(); } return 0;}
背过就好233
注意处理没有环的情况
阅读全文
0 0
- HDU1599 find the mincost route
- hdu1599 find the mincost route
- hdu1599 find the mincost route
- hdu1599 find the mincost route
- HDU1599:find the mincost route
- hdu1599 find the mincost route
- [hdu1599]find the mincost route
- hdu1599——find the mincost route
- HDU1599:find the mincost route(Floyd)
- HDU1599 find the mincost route (Floyd)
- HDU1599 find the mincost route 无向图最小环
- hdu1599 find the mincost route floyd求最小环
- HDU1599:find the mincost route(Floyd最小无向环)
- HDU1599 find the mincost route(floyd求最小环)
- Floyd求最小环 hdu1599 find the mincost route
- HDU1599 find the mincost route (floyd求最小环)
- hdu1599—find the mincost route(floyed最小环)
- find the mincost route
- K
- 使用Mybatis-Generator自动生成代码
- CodeChef:Desik And Divisors(数学 & 二分 & 思维)
- You're Given a String... CodeForces
- [Unity]如果AssetStore的下载无效怎么办
- [hdu1599]find the mincost route
- 数据库
- 网络请求数据之XUtils和Volley
- VS2013+QT5.8.0 过程记录
- VS2013+QT5.8.0 过程记录
- hduoj 2010
- oracle语句管理表_DDL
- 05-CSS基本学习
- 超详细:常用的设计模式汇总