题目大意:

求一个最小环。

用Floyd 求最小环算法。

#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <queue>
#include <cmath>
#include <cstring>
using namespace std;
#define INF 0xfffffff
#define maxn 260 int G[maxn][maxn], dist[maxn][maxn];
int Pre[maxn][maxn], Path[maxn];
int m, n, CrossNum = ; void SearchPath(int Star,int End)
{
while(Star != End)
{
Path[CrossNum ++] = Star;
Star = Pre[Star][End];
}
Path[CrossNum ++] = Star;
} void Floyd()
{
int MinLoop = INF;
for(int k=; k<=n; k++)
{
for(int i=; i<k; i++)
{
for(int j=i+; j<k; j++)
{
if( dist[i][j] + G[i][k] + G[k][j] < MinLoop )
{
MinLoop = dist[i][j] + G[i][k] + G[k][j];
CrossNum = ;
SearchPath(i,j);
Path[CrossNum++] = k;
}
}
} 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];
Pre[i][j] = Pre[i][k];
}
}
}
}
}
void Init()
{
for(int i=; i<=n; i++)
{
for(int j=; j<=n; j++)
{
dist[i][j] = G[i][j] = INF;
Pre[i][j] = j;
CrossNum = ;
}
}
} int main()
{
while(cin >> n >> m)
{ Init(); for(int i=; i<m; i++)
{
int a, b, c; cin >> a >> b >> c; G[a][b] = G[b][a] = dist[a][b] = dist[b][a] = min(dist[a][b], c);
} Floyd(); if( CrossNum)
{ for(int i=; i<CrossNum - ; i++)
{
printf("%d ", Path[i]);
}
printf("%d\n", Path[CrossNum - ]);
}
else
cout <<"No solution." << endl;
}
return ;
}

POJ 1734 Sightseeing trip的更多相关文章

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

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

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

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

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

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

  4. POJ 1734 Sightseeing trip(Floyd)

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

  5. poj 1734 Sightseeing trip_ 最小环记录路径

    题意:求最出小环,输出路径 #include <iostream> #include<cstdio> using namespace std; #define N 110 #d ...

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

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

  7. POJ 1734:Sightseeing trip

    Sightseeing trip Time Limit: 1000MS Memory Limit: 65536K Total Submissions: Accepted: Special Judge ...

  8. URAL 1004 Sightseeing Trip(最小环)

    Sightseeing Trip Time limit: 0.5 secondMemory limit: 64 MB There is a travel agency in Adelton town ...

  9. POJ 1637 Sightseeing tour(最大流)

    POJ 1637 Sightseeing tour 题目链接 题意:给一些有向边一些无向边,问能否把无向边定向之后确定一个欧拉回路 思路:这题的模型很的巧妙,转一个http://blog.csdn.n ...

随机推荐

  1. 第一个 Python 程序 - Email Manager Demo

    看了一些基础的 Python 新手教程后,深深感觉到 Python 的简洁与强大,这是我的第一个 Python Demo.下面是完整代码与执行截图. 代码: # encoding: utf-8 ''' ...

  2. Qt深入:不能不知道的Type、Attribute和Flags

    Qter高手与新手的区别在于:知道还是不知道 Qt不是开发语言,所以无所谓谁厉害.但使用他的Qter却有着差异,也许是面向对象语言本身的.或者实际经验上的.而对于Qt本身来说,高手与新手最显著的差异在 ...

  3. [转] add-apt-repository

    PS: 有些项目提供的是deb 地址,那么把deb地址加到repository里,下面是一个例子: sudo apt-get update sudo add-apt-repository 'deb h ...

  4. RunTime 应用实例–关于埋点的思考

    埋点是现在很多App中都需要用到的,这个问题可能每个人都能处理,但是怎样来减少埋点所带来的侵入性,怎样用更加简洁的方式来处理埋点问题,怎样减少误埋,如果上线了发现少埋了怎么办?下面是本文讨论的重点: ...

  5. 使用downloadmanager调用系统的下载

    /** * 文件名 UpdateDownload.java * 包含类名列表 com.issmobile.numlibrary.tool * 版本信息  版本号  * 创建日期 2014年7月14日  ...

  6. ubuntu wine卸载程序并删除图标

    卸载ubuntu 下用wine安装的程序,可以用wine uninstaller命令,打开 添加/删除程序界面,进行删除程序操作:

  7. COGS 445. [HAOI2010]最长公共子序列

    #include<iostream> #include<cstdio> #include<cstring> #define mod 100000000 #defin ...

  8. oracle 自治事物 -- autonomous transaction

    一 使用规则 : 在begin 之前申明  : PRAGMA AUTONOMOUS_TRANSACTION; 二 使用理解:autonomous transaction 是一个独立的事务,这一点是理解 ...

  9. MiniProfiler.EF6监控调试MVC5和EF6的性能

    转自:蓝狐学MVC教程 以前开发Webform的时候可以开启trace来跟踪页面事件,这对于诊断程序的性能是有很大的帮助的,起到事半功倍的作用,今天我就来谈用mvc开 发项目的调试和性能监控.EF框架 ...

  10. asp.net中过滤器的两种写法

    1.写在一个单独的类库中在web.config中进行配置 <httpModules> <add name="" type="类的全名称,程序集的名称&q ...