HDU 1599 find—— the mincost route
来源:互联网 发布:sql right函数 编辑:程序博客网 时间:2024/06/15 20:35
题意可以理解为求有至少带3个节点的环的最小值。
#include<cstdio>#include<iostream>#include<cstring>using namespace std;#define INF 100001int map[102][102],dis[102][102],num[102];int min(int a,int b){return a<b?a:b;}int main(){int n,m,s,e,cost,ans;int i,j,k;while(scanf("%d%d",&n,&m)!=EOF){memset(num,0,sizeof(num));for(i=1;i<=n;i++)for(j=1;j<=n;j++)map[i][j]=INF;for(i=1;i<=m;i++){scanf("%d%d%d",&s,&e,&cost);if(map[s][e]>cost)map[s][e]=map[e][s]=cost;}ans=INF;for(i=1;i<=n;i++)for(j=1;j<=n;j++)dis[i][j]=map[i][j];for(k=1;k<=n;k++){for(i=1;i<=k;i++){for(j=1;j<i;j++){ans= min(ans,dis[i][j]+map[i][k]+map[k][j]);}}for(i=1;i<=n;i++)for(j=1;j<=n;j++){dis[i][j]=min(dis[i][j],dis[i][k]+dis[k][j]);}}if(ans==INF)cout<<"It's impossible."<<endl;elsecout<<ans<<endl;}return 0;}
- HDU 1599 find—— the mincost route
- hdu 1599 find the mincost route
- HDU 1599 find the mincost route
- hdu 1599 find the mincost route
- hdu 1599 find the mincost route
- HDU 1599 find the mincost route
- HDU 1599 find the mincost route
- hdu 1599 find the mincost route
- HDU 1599 find the mincost route
- hdu 1599 find the mincost route
- hdu 1599 find the mincost route
- HDU 1599 find the mincost route
- hdu 1599 find the mincost route
- HDU 1599 find the mincost route
- 【HDU 1599 find the mincost route】
- HDU 1599 find the mincost route
- 【HDU 1599 find the mincost route 】
- HDU 1599 find the mincost route
- IOS第十二天——Obj-C++
- PHP注销删除Session变量的通用方法
- DOCSIS config file-IPv4 Packet Classification Encodings
- php配置session相关知识
- Mybatis上路_05-使用命令行自动生成
- HDU 1599 find—— the mincost route
- 求数组的连续子数组之和的最大值
- POI 解析Excel(兼容 2003,2007)
- WSAAsyncSelect模式编程
- 齐博cms任意登陆漏洞
- 关于Hibernate中的对象图关系转换:游离、持久、自由状态
- linux正则表达式 grep egrep用法
- 计算分数的精确值
- 'ADB server didn't ACK'的解决办法