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 ...
随机推荐
- Coursera Algorithms week1 算法分析 练习测验: 3Sum in quadratic time
题目要求: Design an algorithm for the 3-SUM problem that takes time proportional to n2 in the worst case ...
- Webpack 2.0 的文档
Webpack 2.0 的文档 https://webpack.js.org/get-started/
- C语言程序创建文件
#include <stdio.h>#include <stdlib.h>int main() { FILE *fp;if((fp=fopen("g:\\a.txt& ...
- EasyUI TreeGrid 悬浮效果
/* 鼠标悬停扩展*/ (function (hasgrid) { if (hasgrid) { /** * 表格提示 */ $.extend($.fn.datagrid.methods, { too ...
- python 3:str.upper()与str.lower()(使字符串字母全部大写或小写)
name = "Hello,World! Hello,Python!" print(name.upper()) #字母全部大写 print(name.lower()) #字母全部小 ...
- B - IQ test
Problem description Bob is preparing to pass IQ test. The most frequent task in this test is to find ...
- dom转换成jquery对象
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/stri ...
- PHP序列化 反序列化
序列化是将变量转换为可保存或传输的字符串的过程:反序列化就是在适当的时候把这个字符串再转化成原来的变量使用.这两个过程结合起来,可以轻松地存储和传输数据,使程序更具维护性. 1. serialize和 ...
- java Queue中 remove/poll, add/offer, element/peek区别
offer,add区别: 一些队列有大小限制,因此如果想在一个满的队列中加入一个新项,多出的项就会被拒绝. 这时新的 offer 方法就可以起作用了.它不是对调用 add() 方法抛出一个 unche ...
- 《3D建模初步》参考资料
本门课程主要从3D打印角度来介绍3D建模的简单知识.课程采用免费的3D CAD软件Autodesk 123D Design来具体演示一些简单模型的构建方法,并介绍3D打印有关的知识与方法. 课程以&l ...