find the mincost route(floyd变形 无向图最小环)
Time Limit: 1000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1630 Accepted Submission(s): 664
接下来的M行里,每行包括3个整数a,b,c.代表a和b之间有一条通路,并且需要花费c元(c <= 100)。
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std; const int INF = ;
const int N = ;
int n,m;
int map[N][N],dis[N][N];
int ans; void floyd()
{
int i,j,k;
ans = INF;
for(k = ; k <= n; k++)
{
for(i = ; i < k; i++)
{
for(j = i+; j < k; j++)
{
ans = min(ans,dis[i][j]+map[j][k]+map[k][i]);
}
} for(i = ; i <= n; i++)
{
for(j = ; j <= n; j++)
{
if(dis[i][j] > (dis[i][k]+dis[k][j]))
dis[i][j] = dis[i][k]+dis[k][j];
}
}
}
}
int main()
{
while(~scanf("%d %d",&n,&m))
{
for(int i = ; i <= n; i++)
{
for(int j = ; j <= n; j++)
{
map[i][j] = INF;
dis[i][j] = INF;
}
} while(m--)
{
int u,v,w;
scanf("%d %d %d",&u,&v,&w);
if(map[u][v] > w)
{
map[u][v] = map[v][u] = w;
dis[u][v] = dis[v][u] = w;
}
}
floyd();
if(ans < INF)
printf("%d\n",ans);
else printf("It's impossible.\n"); }
return ;
}
find the mincost route(floyd变形 无向图最小环)的更多相关文章
- 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 ...
- hdu1599 find the mincost route floyd求出最小权值的环
find the mincost route Time Limit: 1000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/O ...
- HD1599 find the mincost route(floyd + 最小环)
题目链接 题意:求最小环 第一反应时floyd判断,但是涉及到最少3个点,然后就不会了,又想的是 双联通分量,这个不知道为什么不对. Floyd 判断 最小环 #include <iostrea ...
- FZU 2090 旅行社的烦恼 floyd 求无向图最小环
题目链接:旅行社的烦恼 题意是求无向图的最小环,如果有的话,输出个数,并且输出权值. 刚刚补了一发floyd 动态规划原理,用了滑动数组的思想.所以,这个题就是floyd思想的变形.在k从1到n的过程 ...
- poj1734 Sightseeing trip(Floyd求无向图最小环)
#include <iostream> #include <cstring> #include <cstdio> #include <algorithm> ...
- 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://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 ...
随机推荐
- atoi、stoi、strtoi区别
首先atoi和strtol都是c里面的函数,他们都可以将字符串转为int,它们的参数都是const char*,因此在用string时,必须调c_str()方法将其转为char*的字符串.或者atof ...
- Navicat Premium 自动备份mysql和sqlserver
mysql篇: 1.点击计划 2.点击新建处理作业 3.选择需要备份的数据库,上级可用任务 4.点击保存按钮,输入保存文件名 5.保存后点击设置计划任务 6.计划里新建保存时间,应用后输入系统密码即可 ...
- JavaScript正则验证数字、英文、电话号、身份证号、邮箱地址、链接地址等
验证是否为数字:/^[0-9]*$/验证是否为汉字:/^[\u4e00-\u9fa5],{0,}$/验证x-y位的数字:/^\d{x,y}$/验证由26个英文字母组成的字符串:/^[A-Za-z]+$ ...
- 使用XLinq.XElement读取带Namespace(命名空间)的XML
简介 本文主要介绍通过XELemet去读取含有namespaces(xmlns)的XML,这也是偶然间发现这个问题的,一个群里的小伙伴突然问起这个,以此记录一下. 背景 一个XML文档可能包括来自多个 ...
- Asp.Net 注册 邮箱激活
数据库 表的设计 State为用户状态 0为禁用 1为可用 默认为0,下面有个UserGUID,这个字段将来用于激活账户 首先你要写一个表单,验证码神马的,这个我就不写了..直接写处理的 代码在 ...
- javascript事件详解1
事件流讲解来袭,嘎嘎嘎嘎嘎 ---------------------------------------------------------------- 1.事件流:描述的是在页面中接受事件的顺序 ...
- PHP算法 《图》 之 理论基础
转载自:http://www.cnblogs.com/skywang12345/p/3691463.html Ⅰ 图的基本概念 1. 图的定义 定义:图(graph)是由一些点(vertex)和这些点 ...
- 数据挖掘相关的10个问题[ZZ]
NO.1 Data Mining 和统计分析有什么不同? 硬要去区分Data Mining和Statistics的差异其实是没有太大意义的.一般将之定义为Data Mining技术的CART.CHAI ...
- MongoDB 与传统关系型数据库mysql比较
与关系型数据库相比,MongoDB的优点: 转载自 http://blog.sina.com.cn/s/blog_966e430001019s8v.html①弱一致性(最终一致),更能保证用户的访问 ...
- php函数——『解析 xml数据』
<?php //该文件是 //$raw_post_data = file_get_contents('php://input'); //file_put_contents('a.txt', $r ...