题意:求最出小环,输出路径

#include <iostream>
#include<cstdio>
using namespace std;
#define N 110
#define INF 0xffffff
int map[N][N],n,m,dist[N][N],pre[N][N],path[N];
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
void floyd(){
int i,j,k,ans=INF,num,p;
for(i=0;i<=n;i++)
for(j=0;j<=n;j++)
dist[i][j]=map[i][j];
for(k=1;k<=n;k++){
for(i=1;i<k;i++)
for(j=i+1;j<k;j++){
int tmp=dist[i][j]+map[i][k]+map[k][j];
if(tmp<ans){
ans=dist[i][j]+map[i][k]+map[k][j];
p=j;
num=0;
while(p!=i){
path[num++]=p;
p=pre[i][p];
}
path[num++]=i;
path[num++]=k;
}
} for(i=1;i<=n;i++)
for(j=1;j<=n;j++){
int tmp=dist[i][k]+dist[k][j];
if(dist[i][j]>dist[i][k]+dist[k][j]){
dist[i][j]=dist[i][k]+dist[k][j];
pre[i][j]=pre[k][j];
}
}
}
if(ans==INF)
printf("No solution.\n");
else{
printf("%d",path[0]);
for(i=1;i<num;i++)
printf(" %d",path[i]);
puts("");
}
}
int main(int argc, char** argv) {
int i,j,a,b,d;
// freopen("in.txt","r",stdin);
while(scanf("%d%d",&n,&m)!=EOF){
for(i=1;i<=n;i++)
for(j=1;j<=n;j++){
map[i][j]=INF;
pre[i][j]=i;
}
for(i=0;i<m;i++){
scanf("%d%d%d",&a,&b,&d);
if(map[a][b]>d)
map[a][b]=map[b][a]=d;
}
floyd();
}
return 0;
}

poj 1734 Sightseeing trip_ 最小环记录路径的更多相关文章

  1. POJ.3894 迷宫问题 (BFS+记录路径)

    POJ.3894 迷宫问题 (BFS+记录路径) 题意分析 定义一个二维数组: int maze[5][5] = { 0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, ...

  2. POJ 1734.Sightseeing trip (Floyd 最小环)

    Floyd 最小环模板题 code /* floyd最小环,记录路径,时间复杂度O(n^3) 不能处理负环 */ #include <iostream> #include <cstr ...

  3. POJ 1734 Sightseeing trip(Floyd)

    题目传送门 题目中文翻译: Description 桑给巴尔岛上的阿德尔顿镇有一家旅行社,它已决定为其客户提供除了许多其他名胜之外的景点.为了尽可能地从景点赚取收入,该机构已经接受了一个精明的决定:有 ...

  4. POJ 1734 Sightseeing trip(无向图最小环+输出路径)

    题目链接 #include <cstdio> #include <string> #include <cstring> #include <queue> ...

  5. poj 1734 Sightseeing trip判断最短长度的环

    Sightseeing trip Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 5590   Accepted: 2151 ...

  6. POJ 1734 Sightseeing trip

    题目大意: 求一个最小环. 用Floyd 求最小环算法. #include <iostream> #include <cstdlib> #include <cstdio& ...

  7. poj 1734 floyd求最小环,可得到环上的每个点

    #include<stdio.h> #include<string.h> #define inf  100000000 #define N 110 #define min(a, ...

  8. Sightseeing trip POJ - 1734 -Floyd 最小环

    POJ - 1734 思路 : Floyd 实质 dp ,优化掉了第三维. dp [ i ] [ j ] [ k ] 指的是前k个点优化后    i  ->  j   的最短路. 所以我们就可以 ...

  9. POJ 1734 求最小环路径 拓展Floyd

    九野的博客,转载请注明出处:http://blog.csdn.net/acmmmm/article/details/11888019 题意: n个点 m条无向边 下面m条有权无向边 问图中最小环的路径 ...

随机推荐

  1. CEF中文教程(google chrome浏览器控件) -- Windows下编译Chromium

    CEF中文教程(google chrome浏览器控件) -- CEF简介 2013-04-10 16:48 42928人阅读 评论(4) 收藏 举报  分类: CEF(2)    目录(?)[+]   ...

  2. WIN7_64位系统安装oracle以及PLSQL方法(不用装32位oracle客户端)

    一.oracle10g安装,比较简单 1.去Oracle网站下载Vista版的Oracle:Oracle Database 10g Release 2 (10.2.0.4) for Microsoft ...

  3. 【剑指offer】面试题22:栈的压入、弹出序列

    题目: 输入两个整数序列,第一个序列表示栈的压入顺序,请判断第二个序列是否为该栈的弹出顺序.假设压入栈的所有数字均不相等.例如序列1,2,3,4,5是某栈的压入顺序,序列4,5,3,2,1是该压栈序列 ...

  4. python-pcap模块解析mac地址

    python-pcap模块解析mac地址 作者:vpoet mail:vpoet_sir@163.com import pcap import binascii a = pcap.pcap() a.s ...

  5. cc150 Chapter 2 | Linked Lists 2.6 Given a circular linked list, implement an algorithm which returns node at the beginning of the loop.

    2.6Given a circular linked list,  implement an algorithm which returns the node at the beginning of ...

  6. 【UVA 11997 K Smallest Sums】优先级队列

    来自<训练指南>优先级队列的例题. 题目链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=18702 题意:给定 ...

  7. UML_活动图

    一.活动图的组成元素 Activity Diagram Element 1.活动状态图(Activity) 2.动作状态(Actions) 3.动作状态约束(Action Constraints) 4 ...

  8. UGUI Image控件

    今天一起学习Image控件O(∩_∩)O~ 介绍一下基本的属性 Source:Image:               指定图片源, 图片设置2DSprite(2D and UI)格式Color:   ...

  9. mysql的wait_timeout配置

    mysql数据库有一个wait_timeout的配置,默认值为28800(即8小时). 在默认配置不改变的情况下,如果连续8小时内都没有访问数据库的操作,再次访问mysql数据库的时候,mysql数据 ...

  10. os x 10.10 測试版系统下载 swift语言学习资料下载

    http://pan.baidu.com/s/1eQ5oj1S               这是下载地址 ! 刚学完oc 就出了 swift!这----  只是还是非常高兴看了一点swith得东西感觉 ...