hdu 1599 find the mincost route 最小环
题目链接:HDU - 1599
接下来的M行里,每行包括3个整数a,b,c.代表a和b之间有一条通路,并且需要花费c元(c <=
100)。
impossible.".
- #include<iostream>
- #include<cstdio>
- #include<cstring>
- #include<cstdlib>
- #include<cmath>
- #include<algorithm>
- #define inf 0x7fffffff
- using namespace std;
- const int maxn=+;
- int n,m;
- int dist[maxn][maxn],edge[maxn][maxn];
- void floyd()
- {
- int ans=;
- for (int i= ;i<=n ;i++)
- {
- for (int j= ;j<=n ;j++)
- dist[i][j]=edge[i][j];
- }
- for (int k= ;k<=n ;k++)
- {
- for (int i= ;i<k ;i++)
- {
- for (int j=i+ ;j<k ;j++)
- {
- if (dist[j][i]+edge[i][k]+edge[k][j]<)
- ans=min(ans,dist[j][i]+edge[i][k]+edge[k][j]);
- }
- }
- for (int i= ;i<=n ;i++)
- {
- for (int j= ;j<=n ;j++)
- {
- if (dist[i][j]>dist[i][k]+dist[k][j])
- dist[i][j]=dist[i][k]+dist[k][j];
- }
- }
- }
- if (ans==) printf("It's impossible.\n");
- else printf("%d\n",ans);
- }
- int main()
- {
- while (scanf("%d%d",&n,&m)!=EOF)
- {
- for (int i= ;i<=n ;i++)
- {
- for (int j= ;j<=n ;j++)
- edge[i][j]=;
- edge[i][i]=;
- }
- int x,y,cost;
- for (int i= ;i<m ;i++)
- {
- scanf("%d%d%d",&x,&y,&cost);
- if (edge[x][y]>cost) edge[x][y]=edge[y][x]=cost;
- }
- floyd();
- }
- return ;
- }
hdu 1599 find the mincost route 最小环的更多相关文章
- 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 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(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 (无向图的最小环)
题意: 给一个带权无向图,求其至少有3个点组成的环的最小权之和. 思路: (1)DFS可以做,实现了确实可以,只是TLE了.量少的时候应该还是可以水一下的.主要思路就是,深搜过程如果当前点搜到一个点访 ...
- hdu 1599 find the mincost route
http://acm.hdu.edu.cn/showproblem.php?pid=1599 floyd找最小环. #include <cstdio> #include <cstri ...
- HDU 1599 find the mincost route (最短路 floyd)
题目链接 Problem Description 杭州有N个景区,景区之间有一些双向的路来连接,现在8600想找一条旅游路线,这个路线从A点出发并且最后回到A点,假设经过的路线为V1,V2,....V ...
随机推荐
- springbootDay03 cookie和session 购物车技术
一.会话技术 1. 什么是会话 在计算机术语中,会话指的是客户端和服务器交互通讯的过程.简单的理解,大家可以看成是两个普通的人在打电话.一次电话从通话开始到挂断,可以看成是会话. 会话的特征 会话能够 ...
- 批量部署ssh免密登陆
#!/bin/bash#set -xservers="10.254.192.xx10.254.192.xx10.254.192.xx"passwd="xxxxxxxx&q ...
- python3.6操作mysql
1.通过 pip 安装 pymysql 进入 cmd 输入 pip install pymysql 回车等待安装完成: 安装完成后出现如图相关信息,表示安装成功. 2.测试连接 import ...
- 【bzoj4010】[HNOI2015]菜肴制作 拓扑排序+堆
题目描述 给你一张有向图,问:编号-位置序(即每个编号的位置对应的序列)最小(例如1优先出现在前面,1位置相同的2优先出现在前面,以此类推)的拓扑序是什么? 输入 第一行是一个正整数D,表示数据组数. ...
- hdu 1172 猜数字
猜数字 Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submi ...
- 三十道DP练习(持续更新)(pw:DP)
前言: 话说DP这种纯考思维的题目,总是让我很伤脑筋,一些特别简单的DP我都常常做不出来,所以革命从现在(2018-05-01)开始,努力多刷点DP的练习-. 1.顺序对齐(align) 时间:201 ...
- Windows2008下RDP采用私有CA服务器证书搭建文档
在中小型公司建立企业根证书颁发机构 (CA) http://www.microsoft.com/china/smb/issues/sgc/articles/build_ent_root_ca.mspx ...
- 转:LinkedHashMap使用(可以用来实现LRU缓存)
1. LinkedHashMap概述: LinkedHashMap是HashMap的一个子类,它保留插入的顺序,如果需要输出的顺序和输入时的相同,那么就选用LinkedHashMap. LinkedH ...
- 自己写的enum转换的一个扩展,
public static String ToEnumName(this int? source, Type e) { if (!source.HasValue) throw new Argument ...
- webservice跨域文件,好多年前的东西,远程调用,js服务器端使用,可以远程调用
1.clientaccesspolicy.xml <?xml version="1.0" encoding="utf-8" ?> <acces ...