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. 【BZOJ2067】[Poi2004]SZN

    题解: 比上一题水多了 首先树上贪心,肯定要考虑儿子 然后我们会发现这个东西就是要先把儿子连起来 然后如果儿子个数为奇数我们可以把这一条和它连向父亲的并在一起 由于根没有父亲所以要单独考虑 答案就是s ...

  2. [转]Centos 查看端口占用情况和开启端口命令

    http://www.cnblogs.com/xqzt/p/4919191.html 1.Centos 查看端口占用 比如查看 80 端口占用情况使用如下命令: lsof -i tcp:80 2.列出 ...

  3. 【转】Windows Server 2008 R2下安装 .net framework3.5

    原文地址:http://hi.baidu.com/tonny_dxf/item/6831bcdc3d7c06e7b2f7777c      [你必须用角色管理工具安装.net framework3.5 ...

  4. Python连接mysql出错,_mysql_exceptions.OperationalError: (1045, "Access denied for user 'root'@'localhost' (using password: YES)")

  5. Linux centos7安装python3并且不影响python2

    一.安装依赖 yum -y groupinstall "Development tools" yum -y install zlib-devel bzip2-devel opens ...

  6. 高性能之css

    避免使用@import 有两种方式加载样式文件,一种是link元素,另一种是CSS 2.1加入@import.而在外部的CSS文件中使用@import会使得页面在加载时增加额外的延迟.虽然规则允许在样 ...

  7. Codeforces Gym100543G Virus synthesis 字符串 回文自动机 动态规划

    原文链接https://www.cnblogs.com/zhouzhendong/p/CF-100543G.html 题目传送门 - CF-Gym100543G 题意 你可以对一个字符串进行以下两种操 ...

  8. 009 spring boot中文件的上传与下载

    一:任务 1.任务 文件的上传 文件的下载 二:文件的上传 1.新建一个对象 FileInfo.java package com.cao.dto; public class FileInfo { pr ...

  9. php分词工具scws

    分词工具   sphinx  支持php版本5.2.2~6.0因此选用scws 文档地址 http://www.xunsearch.com/scws/docs.php#instscws 简单的demo ...

  10. 使用EndNote在Word中插入参考文献

    以百度文库为例,首先找到我们要插入的参考文献,比如 搜索关键词,然后下需要的论文下面点击引用 得到 点击下面导出链接的EndNote,会下载一个.enw文件 找到此文件并双击打开后即已经导入到EndN ...