https://vjudge.net/problem/POJ-3268

一开始floyd超时了。。

对正图定点求最短,对逆图定点求最短,得到任意点到定点的往返最短路。

 #include<iostream>
#include<cstdio>
#include<queue>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<stack>
#define lson l, m, rt<<1
#define rson m+1, r, rt<<1|1
#define INF 0x3f3f3f3f
typedef unsigned long long ll;
using namespace std;
int t[][], rt[][];
int d[], rd[], vis[];
int n, m, x, a, b, T;
void dijkstra(int dist[], int a[][])
{
memset(vis, , sizeof(vis));
for(int i = ; i <= n; i++){
dist[i] = INF;
}
dist[x] = ;
for(int i = ; i <= n; i++){
int mini = INF, k = -;
for(int j = ; j <= n; j++){
if(!vis[j]&&mini > dist[j]){
mini = dist[j];
k = j;
}
}
vis[k] = ;
for(int j = ; j <= n; j++){
if(!vis[j]&&dist[j] > dist[k]+a[k][j]){
dist[j] = dist[k]+a[k][j];
}
}
}
}
int main()
{
cin >> n >> m >> x;
for(int i = ; i <= n; i++){
for(int j = ; j <= n; j++){
t[i][j] = INF; rt[i][j] = INF;
}
}
for(int i = ; i <= m; i++){
cin >> a >> b >> T;
t[a][b] = T;//图
rt[b][a] = T;//逆图
}
dijkstra(d, t);
dijkstra(rd, rt);
int maxm = -INF;
for(int i = ; i <= n; i++){
if(d[i]!=INF&&rd[i]!=INF&&d[i]+rd[i] > maxm){
maxm = d[i]+rd[i];
}
}
cout << maxm << endl;
return ;
}

poj3268 Silver Cow Party(两次dijkstra)的更多相关文章

  1. POJ-3268 Silver Cow Party---正向+反向Dijkstra

    题目链接: https://vjudge.net/problem/POJ-3268 题目大意: 有编号为1-N的牛,它们之间存在一些单向的路径.给定一头牛的编号X,其他牛要去拜访它并且拜访完之后要返回 ...

  2. poj3268 Silver Cow Party(两次SPFA || 两次Dijkstra)

    题目链接 http://poj.org/problem?id=3268 题意 有向图中有n个结点,编号1~n,输入终点编号x,求其他结点到x结点来回最短路长度的最大值. 思路 最短路问题,有1000个 ...

  3. POJ3268 Silver Cow Party(dijkstra+矩阵转置)

    Silver Cow Party Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 15156   Accepted: 6843 ...

  4. POJ 3268 Silver Cow Party (双向dijkstra)

    题目链接:http://poj.org/problem?id=3268 Silver Cow Party Time Limit: 2000MS   Memory Limit: 65536K Total ...

  5. POJ3268 Silver Cow Party —— 最短路

    题目链接:http://poj.org/problem?id=3268 Silver Cow Party Time Limit: 2000MS   Memory Limit: 65536K Total ...

  6. poj 3268 Silver Cow Party(最短路dijkstra)

    描述: One cow from each of N farms (1 ≤ N ≤ 1000) conveniently numbered 1..N is going to attend the bi ...

  7. POJ 3268 Silver Cow Party 最短路—dijkstra算法的优化。

    POJ 3268 Silver Cow Party Description One cow from each of N farms (1 ≤ N ≤ 1000) conveniently numbe ...

  8. POJ3268 Silver Cow Party Dijkstra最短路

    Description One cow from each of N farms (1 ≤ N ≤ 1000) conveniently numbered 1..N is going to atten ...

  9. POJ3268 Silver Cow Party (建反图跑两遍Dij)

    One cow from each of N farms (1 ≤ N ≤ 1000) conveniently numbered 1..N is going to attend the big co ...

随机推荐

  1. Javascript转义字符串中的特殊字符处理

    Web应用系统中,客户端发送请求到服务器,请求中的字符串参数,在被序列化成json过程中有些特殊字符会被空格代, 导致传递到服务器端再解析的时候,原本的输入参数就会被改变. 目前遇到的特殊字符有加号( ...

  2. Flink--输入数据集Data Sources

    flink在批处理中常见的source flink在批处理中常见的source主要有两大类. 1.基于本地集合的source(Collection-based-source) 2.基于文件的sourc ...

  3. Jnekins+Gitlab代码提交全程配置

    实验环境: 测试机:192.168.2.156 Jenkins:192.168.2.157 Gitlab:192.168.2.158 温馨提示:如果不知道,Jenkins和Gitlab安装过程~可参考 ...

  4. Vue全局API总结

    1.extend用于创建一个子类Vue,用$mount来挂载 <body> <div id="app"></div> <script> ...

  5. Dig

    在 UNIX 和 Linux 下,建议大家使用 dig 命令来代替 nslookup. dig 命令的功能比 nslookup 强大很多,不像 nslookkup 还得 set 来 set 去的,怪麻 ...

  6. Python交互图表可视化Bokeh:7. 工具栏

    ToolBar工具栏设置 ① 位置设置② 移动.放大缩小.存储.刷新③ 选择④ 提示框.十字线 1. 位置设置 import numpy as np import pandas as pd impor ...

  7. Hudson与Jenkins

    Hudson是Jenkins的前身,它们都是基于Java开发的一种持续集成工具,用于监控程序重复的工作,包括: 1.持续的软件版本发布/测试项目. 2.监控外部调用执行的工作. Hudson的特性 1 ...

  8. pythonclass,day1-day2.

    由于是小白,真的一点点的基础都没有,所以压力确实有点大的.全程都是在碰壁,没有明白的地方,装个软件都问题层出不穷,别人几秒钟搞定的,我需要几十分钟,甚至更久...真的是,太强烈的挫败感了,整个人被乌云 ...

  9. 【python】异步IO

    No1: 协程看上去也是子程序,但执行过程中,在子程序内部可中断,然后转而执行别的子程序,在适当的时候再返回来接着执行. 优势: 1.最大的优势就是协程极高的执行效率.因为子程序切换不是线程切换,而是 ...

  10. P1993 小K的农场

    P1993 小K的农场比较裸的差分约束,只是我判负环的时候sb了... 有负环意味着无解 #include<iostream> #include<cstdio> #includ ...