【题目链接】

点击打开链接

【算法】

floyd求最小环

输出路径的方法如下,对于i到j的最短路,我们记pre[i][j]表示j的上一步

在进行松弛操作的时候更新pre即可

【代码】

#include <algorithm>
#include <bitset>
#include <cctype>
#include <cerrno>
#include <clocale>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <limits>
#include <list>
#include <map>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <utility>
#include <vector>
#include <cwchar>
#include <cwctype>
#include <stack>
#include <limits.h>
using namespace std;
#define MAXN 110
const int INF = 1e8; int n,m;
int g[MAXN][MAXN],mp[MAXN][MAXN],pre[MAXN][MAXN]; inline void solve()
{
int ans = INF;
vector< int > res;
for (int k = ; k <= n; k++)
{
for (int i = ; i < k; i++)
{
for (int j = i + ; j < k; j++)
{
if (g[i][j] + mp[j][k] + mp[k][i] < ans)
{
ans = g[i][j] + mp[j][k] + mp[k][i];
res.clear();
int tmp = j;
while (tmp != i)
{
res.push_back(tmp);
tmp = pre[i][tmp];
}
res.push_back(i);
res.push_back(k);
}
}
}
for (int i = ; i <= n; i++)
{
for (int j = ; j <= n; j++)
{
if (g[i][k] + g[k][j] < g[i][j])
{
g[i][j] = g[i][k] + g[k][j];
pre[i][j] = pre[k][j];
}
}
}
}
if (ans == INF)
{
puts("No solution.");
return;
}
for (int i = ; i < res.size() - ; i++) printf("%d ",res[i]);
printf("%d\n",res[res.size()-]);
} int main()
{ scanf("%d%d",&n,&m);
for (int i = ; i <= n; i++)
{
for (int j = ; j <= n; j++)
{
g[i][j] = mp[i][j] = INF;
pre[i][j] = i;
}
}
for (int i = ; i <= m; i++)
{
int u,v,w;
scanf("%d%d%d",&u,&v,&w);
if (w < g[u][v])
g[u][v] = mp[u][v] = g[v][u] = mp[v][u] = w;
}
solve(); return ; }

【POJ 1734】 Sightseeing Trip的更多相关文章

  1. POJ 1734:Sightseeing trip

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

  2. 【POJ 2486】 Apple Tree(树型dp)

    [POJ 2486] Apple Tree(树型dp) Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 8981   Acce ...

  3. bzoj 2295: 【POJ Challenge】我爱你啊

    2295: [POJ Challenge]我爱你啊 Time Limit: 1 Sec  Memory Limit: 128 MB Description ftiasch是个十分受女生欢迎的同学,所以 ...

  4. 【链表】BZOJ 2288: 【POJ Challenge】生日礼物

    2288: [POJ Challenge]生日礼物 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 382  Solved: 111[Submit][S ...

  5. BZOJ2288: 【POJ Challenge】生日礼物

    2288: [POJ Challenge]生日礼物 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 284  Solved: 82[Submit][St ...

  6. BZOJ2293: 【POJ Challenge】吉他英雄

    2293: [POJ Challenge]吉他英雄 Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 80  Solved: 59[Submit][Stat ...

  7. BZOJ2287: 【POJ Challenge】消失之物

    2287: [POJ Challenge]消失之物 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 254  Solved: 140[Submit][S ...

  8. BZOJ2295: 【POJ Challenge】我爱你啊

    2295: [POJ Challenge]我爱你啊 Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 126  Solved: 90[Submit][Sta ...

  9. BZOJ2296: 【POJ Challenge】随机种子

    2296: [POJ Challenge]随机种子 Time Limit: 1 Sec  Memory Limit: 128 MBSec  Special JudgeSubmit: 114  Solv ...

随机推荐

  1. 【转】关于大型网站技术演进的思考(十九)--网站静态化处理—web前端优化—上(11)

    网站静态化处理这个系列马上就要结束了,今天我要讲讲本系列最后一个重要的主题web前端优化.在开始谈论本主题之前,我想问大家一个问题,网站静态化处理技术到底是应该归属于web服务端的技术范畴还是应该归属 ...

  2. [HDU2896]病毒侵袭(AC自动机)

    传送门 题目中文描述,赞! 除了val记录id以外就是模板. 注意:每次数组都要清0.0 ——代码 #include <cstdio> #include <queue> #in ...

  3. python监控tomcat日记文件

    最近写了一个用python监控tomcat日记文件的功能 实现的功能: 监控日记文件中实时过来的记录,统计每分钟各个接口调用次数,统计结果插入oracle #!/usr/bin/python # -* ...

  4. hdu 2438 Turn the corner [ 三分 ]

    传送门 Turn the corner Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Othe ...

  5. poj3694+hdu2460 求桥+缩点+LCA/tarjan

    这个题使我更深理解了TARJAN算法,题意:无向图,每添加一条边后文桥的数量,三种解法:(按时间顺序),1,暴力,每每求桥,听说这样能过,我没过,用的hash判重,这次有俩个参数(n->10w, ...

  6. lombok注解

    官方文档:@EqualsAndHashCode 转:https://blog.csdn.net/zhanlanmg/article/details/50392266 1. 此注解会生成equals(O ...

  7. Java实验--继承与多态

    ---恢复内容开始--- 题目如下: [实验任务一]:面积计算(设计型). 1. 实验要求: 实验报告中要求包括程序设计思想.程序流程图.源代码.运行结果截图.编译错误分析等内容. 2.实验内容: ( ...

  8. iptables防火墙以及网络协议基本原理

    一. Linux 网络安全模型 1. 防火墙: 工作在主机或者网络边缘,对进出报文使用实现定义的规则进行检测,并且由匹配的规则进行处理的一组硬件或者软件.也可能两者结合. 1) 通常使用的防火墙设备 ...

  9. 解决java.util.concurrent.ExecutionException: org.apache.catalina.LifecycleException

    解决: 工程目录.settings\org.eclipse.wst.common.project.facet.core.xml文件中jst.web的version降低到2.5 <?xml ver ...

  10. Scala入门到精通——第二十四节 高级类型 (三)

    作者:摆摆少年梦 视频地址:http://blog.csdn.net/wsscy2004/article/details/38440247 本节主要内容 Type Specialization Man ...