HDU 1599
裸的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的更多相关文章
- hdu 1599 find the mincost route 最小环
题目链接:HDU - 1599 杭州有N个景区,景区之间有一些双向的路来连接,现在8600想找一条旅游路线,这个路线从A点出发并且最后回到A点,假设经过的路线为V1,V2,....VK,V1,那么必须 ...
- 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求最小环 无向图)
传送门: 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 (无向图的最小环)
题意: 给一个带权无向图,求其至少有3个点组成的环的最小权之和. 思路: (1)DFS可以做,实现了确实可以,只是TLE了.量少的时候应该还是可以水一下的.主要思路就是,深搜过程如果当前点搜到一个点访 ...
- hdu 1599 find the mincost route(flyod求最小环)
Problem Description 杭州有N个景区,景区之间有一些双向的路来连接,现在8600想找一条旅游路线,这个路线从A点出发并且最后回到A点,假设经过的路线为V1,V2,....VK,V1, ...
- hdu 1599 find the mincost route_最小环
#include <iostream> #include<cstdio> using namespace std; #define N 110 #define INF 0xff ...
- HDU 1599 find the mincost route (无向图floyd最小环详解)
转载请注明出处:http://blog.csdn.net/a1dark 分析:终于弄懂了floyd的原理.以前的理解一直肤浅.所以一做到floyd应用的题.就拙计了.其实floyd的本质DP.利用前K ...
- HDU 1599 find the mincost route (最短路 floyd)
题目链接 Problem Description 杭州有N个景区,景区之间有一些双向的路来连接,现在8600想找一条旅游路线,这个路线从A点出发并且最后回到A点,假设经过的路线为V1,V2,....V ...
随机推荐
- K-means algorithm----PRML读书笔记
The K-means algorithm is based on the use of squared Euclidean distance as the measure of dissimila ...
- thinkphp的session用法
Session方法用于Session 设置.获取.删除和管理操作. Session 用于Session 设置.获取.删除和管理操作 用法 session($name, $value='') 参数 na ...
- Python 33(1) UDP协议 数据报协议 socketsever模块
一:基于UDP协议通信的套接字 基于UDP协议 只要是套接字,在开发的过程中一定要有服务端和客户端. UDP协议说的就是数据报协议,也就是说,基于UDP协议来发数据,每发一个数据,都是带有报头的数据 ...
- 每日算法——新型在线LCA
在线LCA一般大家都会用倍增吧,时间复杂度O(nlogn),空间复杂度O(nlogn),都是非常严格的复杂度限制,并且各种边界处理比较麻烦,有没有更快更好的办法呢? 我们发现,在树链剖分时,我们不经意 ...
- 最小生成树之Prim算法(最原始最详细入门)
//算法6.8 普里姆算法 #include <iostream> using namespace std; typedef char VerTexType; typedef int Ar ...
- 题解报告:hdu 1850 Being a Good Boy in Spring Festival(尼姆博弈)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1850 Problem Description 一年在外 父母时刻牵挂春节回家 你能做几天好孩子吗寒假里 ...
- 这是一个无效的原路径/url
当我们在SourceTree上新建一个“从URL克隆”的远程项目时,在确认“URL”无误的前提下依然报红色字体“这是一个无效的原路径/URL”错误,我们只需要快捷键“Command + ,”打开Sou ...
- VMware中linux安装jdk
首先安装linux系统 如何将jdk安装包复制到linux中不做概述,可以使用xftp工具,或者Xshell,或者其他方式. 1.下载jdk包:本章使用的为后缀为tar.gz的文件(不需要安装),如j ...
- 使用CMD建立指定格式的文件
一.建立空文件的几种方法1.cd.>a.txtcd.表示改变当前目录为当前目录,即等于没改变:而且此命令不会有输出.>表示把命令输出写入到文件.后面跟着a.txt,就表示写入到a.txt. ...
- 【sqli-labs】 less30 GET- Blind -Impidence mismatch -Having a WAF in front of web application (GET型基于盲注的带有WAF注入)
这次是双引号的,WAF绕过方法不变 http://192.168.136.128/sqli-labs-master/Less-30/login.php?id=1&id=2" and ...