题目链接

floyd找最小环

很好理解

 #include<algorithm>
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<cstdio>
#include<string>
#include<cmath>
#include<ctime>
#include<queue>
#include<stack>
#include<map>
#include<set>
#define rre(i,r,l) for(int i=(r);i>=(l);i--)
#define re(i,l,r) for(int i=(l);i<=(r);i++)
#define Clear(a,b) memset(a,b,sizeof(a))
#define inout(x) printf("%d",(x))
#define douin(x) scanf("%lf",&x)
#define strin(x) scanf("%s",(x))
#define LLin(x) scanf("%lld",&x)
#define op operator
#define CSC main
typedef unsigned long long ULL;
typedef const int cint;
typedef long long LL;
using namespace std;
cint inf=;
void inin(int &ret)
{
ret=;int f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=;ch=getchar();}
while(ch>=''&&ch<='')ret*=,ret+=ch-'',ch=getchar();
ret=f?-ret:ret;
}
int n,m,t,dis[][],mp[][];
int floyd()
{
int ret=inf;
re(k,,n)
{
re(i,,n)if(i!=k)
re(j,,n)if(j!=k&&j!=i)
if(dis[i][j]<inf&&mp[i][k]!=inf&&mp[k][j]!=inf)
ret=min(ret,mp[i][k]+mp[k][j]+dis[i][j]);
re(i,,n)
re(j,,n)
dis[i][j]=min(dis[i][j],dis[i][k]+dis[k][j]);
}
return ret;
}
int main()
{
while(scanf("%d%d",&n,&m)!=EOF)
{
re(i,,n)re(j,,m)dis[i][j]=mp[i][j]=inf;
re(i,,m)
{
int q,w,e;inin(q),inin(w),inin(e);
dis[q][w]=dis[w][q]=mp[q][w]=mp[w][q]=min(dis[q][w],e);
}
int ans=floyd();
if(ans==inf)printf("It's impossible.\n");
else printf("%d\n",ans);
}
return ;
}

hdu1599 find the mincost route的更多相关文章

  1. hdu1599 find the mincost route floyd求出最小权值的环

    find the mincost route Time Limit: 1000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/O ...

  2. hdoj 1599 find the mincost route【floyd+最小环】

    find the mincost route Time Limit: 1000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/O ...

  3. find the mincost route(最小环,最短路,floyd)

    find the mincost route Time Limit: 1000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/O ...

  4. [hdu P1599] find the mincost route

    [hdu P1599] find the mincost route 杭州有N个景区,景区之间有一些双向的路来连接,现在8600想找一条旅游路线,这个路线从A点出发并且最后回到A点,假设经过的路线为V ...

  5. 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 ...

  6. 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 ...

  7. hdu 1599 find the mincost route(无向图的最小环)

    find the mincost route Time Limit: 1000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/O ...

  8. 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 ...

  9. HD1599 find the mincost route(floyd + 最小环)

    题目链接 题意:求最小环 第一反应时floyd判断,但是涉及到最少3个点,然后就不会了,又想的是 双联通分量,这个不知道为什么不对. Floyd 判断 最小环 #include <iostrea ...

随机推荐

  1. RN 获取地理位置

    代码: export default class GeolocationView extends Component { watchID: number; constructor(props){ su ...

  2. darknet的安装及报错解决

    darknet 是YOLO网络的一个框架,安装见官网:https://pjreddie.com/darknet/ 跟着步骤就可以安装好了. 由于官网是全英文的,所以本文根据官网进行中文释义. 本人在按 ...

  3. python基础(9)-迭代器&生成器函数&生成器进阶&推导式

    迭代器 可迭代协议和迭代器协议 可迭代协议 只要含有__iter__方法的对象都是可迭代的 迭代器协议 内部含有__next__和__iter__方法的就是迭代器 关系 1.可以被for循环的都是可迭 ...

  4. 16-Python3 条件控制

    2018-11-20 11:41:15 print('狗狗的年龄兑换*********************************************************') age = ...

  5. cocos2d JS 艺术字特殊符号的显示

    this.setSocreAtion(score, this.tfMoneyList[index],mun); //传入分数与对象,调用下面的函数 setSocreAtion : function ( ...

  6. cocos2d JS-(JavaScript) 基础语法间的函数方法相互调用

    1.函数嵌套函数 function calcuate(opr, a, b) { // 定义函数,opr - -> 符号,a,b - -> 数值 //定义 + 函数 function add ...

  7. java-Unicode与中文的转换

    package utils; import org.apache.commons.lang3.StringUtils; public class UnicodeUtils { public stati ...

  8. C#会对于未赋值的变量/成员变量,给予一个初始值吗?

    如果我有程序如下: C# code   ? 1 2 3 4 5 6 7     public class My     {         public bool b;         public  ...

  9. Self hosted OWIN 绑定地址127.0.0.1,外网无法访问

    static void Main()         {             string baseAddress = "http://localhost:4004/";   ...

  10. Spark学习之路 (十八)SparkSQL简单使用

    一.SparkSQL的进化之路 1.0以前: Shark 1.1.x开始: SparkSQL(只是测试性的)  SQL 1.3.x: SparkSQL(正式版本)+Dataframe 1.5.x: S ...