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 ...
随机推荐
- Android记事本11
昨天: Activity的启动模式. 今天: 分析了一些网上的例子的源码. 遇到问题: 无.
- 【转】Unity3D研究院之设置自动旋转屏幕默认旋转方向
http://www.xuanyusong.com/archives/2871 如下图所示,在处理屏幕默认旋转方向的时候可以在这里进行选择,上下左右一共是4个方向. 策划的需求是游戏采用横屏,但是要求 ...
- SystemTap 用法
SystemTap需要内核符号表: http://ddebs.ubuntu.com/pool/main/l/linux/ 基本语法: next对应C中的return,中途返回: 今晚遗留了两个问题: ...
- kindeditor编辑器获取不到修改后的新文本
在编辑文章的功能中,文章内容使用了kindeditor编辑器进行处理,但是修改文本后保存时发现获取到的内容还是修改前的文本内容. 引用编辑器的标签: <textarea id="txt ...
- 方伯伯的OJ ( onlinejudge )
方伯伯的OJ 题目描述 方伯伯正在做他的OJ.现在他在处理OJ 上的用户排名问题. OJ 上注册了n 个用户,编号为1 ∼ n,一开始他们按照编号排名.方伯伯会按照心情对这些用户做以下四种操作,修改用 ...
- HDU 5366 dp 递推
The mook jong Accepts: 506 Submissions: 1281 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65 ...
- bzoj3643 Phi的反函数
传送门:http://www.lydsy.com/JudgeOnline/problem.php?id=3643 [题解] n = p1^a1*p2^a2*...*pm^am phi(n) = p1( ...
- Activator.CreateInstance;Delegate.CreateDelegate
原文发布时间为:2011-10-11 -- 来源于本人的百度文章 [由搬家工具导入] Activator.CreateInstance:http://msdn.microsoft.com/en-us/ ...
- parallel programming. this causual litery nots represents my recent progress in parallel programming in c#.It`s interesting.
not to say extra words,let`s start the code. pasted below: using System; using System.Collections.Ge ...
- webservice soapheader验证方法
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.We ...