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 ...
随机推荐
- sql 游标使用
declare @PASSDate datetime,@VLPN varchar(50),@VLPNColor varchar(10),@nambers int set @VLPN='';set @V ...
- Python读取不同文件夹下的图片并且分类放到新创建的训练文件夹和标签文件夹
在深度学习的训练时,经常会碰到训练的样本数据集和标签数据集是在一个文件夹中,这个时候我们就不得不进行一些数据的预处理和文件的分类,例如将训练(training data)数据集和标签数据集(label ...
- SQLSTATE[HY000] [2003] Can't connect to MySQL server on 'XXX' (13)
SQLSTATE[HY000] [2003] Can't connect to MySQL server on 'XXX' (13) 我可以真见识了 SELinux 的利害了, 这个问题让我找了好长时 ...
- SSM之秒杀系统
利用idea搭建SSM框架,主要利用Maven仓库下载相应的jar包,以下是相关的pom.xml <project xmlns="http://maven.apache.org/POM ...
- Ajax---概念介绍
Ajax不是某种编程语言,是一种在无需重新加载整个网页的情况下能够更新部分网页的技术. 运用HTML和CSS来实现页面,表达信息: 运用XMLHttpRequest和Web服务器进行数据的异步交换: ...
- 【Linux】- 获取root权限命令
1:Redhat系统或者Fedora或者CentOs的Linux发行版,那么在Linux终端输入命令回车: su - root 这样就可以切换到root权限了 2:Ubuntu系统,在Linux终端输 ...
- java实现远程开机
import java.io.IOException; import java.net.*;public class 远程开机 { public static void main(String[] a ...
- [luogu 4240] 毒瘤之神的考验
题目背景 Salamander的家门口是一条长长的公路. 又是一年春天将至,Salamander发现路边长出了一排毒瘤! Salamander想带一些毒瘤回家,但是,这时毒瘤当中钻出来了一个毒瘤之神! ...
- GYM - 101147 F.Bishops Alliance
题意: 一个n*n的棋盘,有m个主教.每个主教都有自己的权值p.给出一个值C,在棋盘中找到一个最大点集.这个点集中的点在同一条对角线上且对于点集中任意两点(i,j),i和j之间的主教数(包括i,j)不 ...
- CF995E Number Clicker 解题报告
CF995E Number Clicker 题目描述 Allen is playing Number Clicker on his phone. He starts with an integer u ...