http://acm.hdu.edu.cn/showproblem.php?pid=1599

floyd找最小环。

 #include <cstdio>
#include <cstring>
#include <algorithm>
#define maxn 200
using namespace std;
const int inf=<<; int g[maxn][maxn],dis[maxn][maxn];
int n,m,a,b,c; int main()
{
while(scanf("%d%d",&n,&m)!=EOF)
{
for(int i=; i<=n; i++)
{
for(int j=; j<=n; j++)
{
g[i][j]=inf;
}
}
for(int i=; i<m; i++)
{
scanf("%d%d%d",&a,&b,&c);
g[a][b]=g[b][a]=min(g[a][b],c);
}
for(int i=; i<=n; i++)
{
for(int j=; j<=n; j++)
{
dis[i][j]=g[i][j];
}
}
int min1=inf;
for(int k=; k<=n; k++)
{
for(int i=; i<k; i++)
{
for(int j=; j<i; j++)
{
min1=min(min1,dis[i][j]+g[i][k]+g[k][j]);
}
}
for(int i=; i<=n; i++)
{
for(int j=; j<=n; j++)
{
dis[i][j]=min(dis[i][j],dis[i][k]+dis[k][j]);
}
}
}
if(min1==inf)
printf("It's impossible.\n");
else
printf("%d\n",min1);
}
return ;
}

hdu 1599 find the mincost route的更多相关文章

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

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

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

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

  4. hdu 1599 find the mincost route 最小环

    题目链接:HDU - 1599 杭州有N个景区,景区之间有一些双向的路来连接,现在8600想找一条旅游路线,这个路线从A点出发并且最后回到A点,假设经过的路线为V1,V2,....VK,V1,那么必须 ...

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

  6. HDU 1599 find the mincost route (无向图的最小环)

    题意: 给一个带权无向图,求其至少有3个点组成的环的最小权之和. 思路: (1)DFS可以做,实现了确实可以,只是TLE了.量少的时候应该还是可以水一下的.主要思路就是,深搜过程如果当前点搜到一个点访 ...

  7. hdu 1599 find the mincost route(flyod求最小环)

    Problem Description 杭州有N个景区,景区之间有一些双向的路来连接,现在8600想找一条旅游路线,这个路线从A点出发并且最后回到A点,假设经过的路线为V1,V2,....VK,V1, ...

  8. HDU 1599 find the mincost route (无向图floyd最小环详解)

    转载请注明出处:http://blog.csdn.net/a1dark 分析:终于弄懂了floyd的原理.以前的理解一直肤浅.所以一做到floyd应用的题.就拙计了.其实floyd的本质DP.利用前K ...

  9. HDU 1599 find the mincost route (最短路 floyd)

    题目链接 Problem Description 杭州有N个景区,景区之间有一些双向的路来连接,现在8600想找一条旅游路线,这个路线从A点出发并且最后回到A点,假设经过的路线为V1,V2,....V ...

随机推荐

  1. SaltStack运行任务卡住了,怎么办?

    将相关的JOB ID杀死即可. salt-run jobs.active salt "*" saltutil.signal_job JOBID 15

  2. 智能卡安全机制比较系列(三) MPCOS

    MPCOS是金普斯早期推出的一款多应用支付芯片卡操作系统,支持ISO7816以及PCOS的数据格式和命令.MPCOS具有两级目录文件结构,即MF下可以有一级DF,每个DF下最多可创建63个EF. MP ...

  3. QT中窗口刷新事件的学习总结

    一.主要理解一下几个方法和属性: 1.QWidget * QScrollView::viewport () const 2.void QWidget::paintEvent ( QPaintEvent ...

  4. Java7新语法 -try-with-resources

    http://docs.oracle.com/javase/7/docs/technotes/guides/language/try-with-resources.html The try-with- ...

  5. cp 提示 overwrite 问题

    cp 提示 overwrite 问题 copy -f 文件的时候仍然提示覆盖问题,很诧异,咨询SA,果然 cp -i 强制要求覆盖文件的时候确认,-f 也不起作用,大大的不爽[root@erpappd ...

  6. CoreData Multiple Context性能分析-读书笔记

    From: http://floriankugler.com/blog/2013/4/29/concurrent-core-data-stack-performance-shootout  http: ...

  7. virtIO驱动安装

  8. c语言const

    const关键字 const和指针结合,共有4种形式 const int *p; p是一个指针,指针指向一个int型数据.p所指向的是个常量. int const *p; p是一个指针,指针指向一个i ...

  9. c语言结构体2之变量赋值于字符串

    #include <stdio.h> #include <stdlib.h> struct dangdang { ]; ]; ]; int num; int bugnum; ] ...

  10. hdu1429之BFS

    胜利大逃亡(续) Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total S ...