POJ 3268 (dijkstra变形)
题目链接 :http://poj.org/problem?id=3268
Description
One cow from each of N farms (1 ≤ N ≤ 1000) conveniently numbered 1..N is going to attend the big cow party to be held at farm #X (1 ≤ X ≤ N). A total of M (1 ≤ M ≤ 100,000) unidirectional (one-way roads connects pairs of farms; road i requires Ti (1 ≤ Ti ≤ 100) units of time to traverse.
Each cow must walk to the party and, when the party is over, return to her farm. Each cow is lazy and thus picks an optimal route with the shortest time. A cow's return route might be different from her original route to the party since roads are one-way.
Of all the cows, what is the longest amount of time a cow must spend walking to the party and back?
Input
Lines 2..M+1: Line i+1 describes road i with three space-separated integers: Ai, Bi, and Ti. The described road runs from farm Ai to farm Bi, requiring Ti time units to traverse.
Output
Sample Input
4 8 2
1 2 4
1 3 2
1 4 7
2 1 1
2 3 5
3 1 2
3 4 4
4 2 3
Sample Output
10
Hint
#include<cstdio>
#include<cstring>
#include<cmath>
#include<iostream>
#include<algorithm>
using namespace std;
const int N = 1e4+10;
int e[N][N],dis[N],book[N],ans[N];
int inf = 99999999;
int n,m,x,i,j,t1,t2,t3;
void disk(){
memset(dis,0,sizeof(dis));
for(i = 1; i <= n; i++){
dis[i] = e[x][i];
}
memset(book,0,sizeof(book));
book[x] = 1;
int min = inf,h;
for(i = 1; i <= n; i++){
min = inf;
for(j = 1; j <= n; j++){
if(book[j] == 0 && dis[j] < min){
min = dis[j];
h = j;
}
}
book[h] = 1;
for(int v = 1; v <= n; v++){
if(dis[v] > dis[h] + e[h][v]){
dis[v] = dis[h] + e[h][v];
}
}
}
}
void change(){ //倒置所有的边
for(i = 1; i <= n; i++){
for(j = 1; j <= i; j++){
swap(e[i][j],e[j][i]);
}
}
}
int main()
{
scanf("%d%d%d",&n,&m,&x);
memset(ans,0,sizeof(ans));
for(i = 1; i <= n; i++){
for(j = 1; j <= n; j++){
if(i == j){
e[i][j] = 0;
}
else{
e[i][j] = inf;
}
}
}
for(i = 1; i <= m; i++){
scanf("%d%d%d",&t1,&t2,&t3);
e[t1][t2] = t3;
}
disk();
for(i = 1; i <= n; i++){
ans[i] += dis[i];
}
change();
disk();
for(i = 1; i <= n; i++){
ans[i] += dis[i];
}
int max = 0;
for(i = 1; i <= n; i++){
if(max < ans[i] && ans[i] < inf){
max = ans[i];
}
}
printf("%d\n",max);
return 0;
}
POJ 3268 (dijkstra变形)的更多相关文章
- POJ 3268 Dijkstra+priority_queue或SPFA
思路:正向建边,一遍Dijkstra,反向建边,再一遍Dijkstra.ans加在一起输出最大值. (SPFA也行--) // by SiriusRen #include <queue> ...
- DIjkstra(反向边) POJ 3268 Silver Cow Party || POJ 1511 Invitation Cards
题目传送门 1 2 题意:有向图,所有点先走到x点,在从x点返回,问其中最大的某点最短路程 分析:对图正反都跑一次最短路,开两个数组记录x到其余点的距离,这样就能求出来的最短路以及回去的最短路. PO ...
- POJ.1797 Heavy Transportation (Dijkstra变形)
POJ.1797 Heavy Transportation (Dijkstra变形) 题意分析 给出n个点,m条边的城市网络,其中 x y d 代表由x到y(或由y到x)的公路所能承受的最大重量为d, ...
- POJ 3268 Silver Cow Party 最短路—dijkstra算法的优化。
POJ 3268 Silver Cow Party Description One cow from each of N farms (1 ≤ N ≤ 1000) conveniently numbe ...
- POJ 3268——Silver Cow Party——————【最短路、Dijkstra、反向建图】
Silver Cow Party Time Limit:2000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Su ...
- NYOJ 1248 海岛争霸(Dijkstra变形——最短路径最大权值)
题目链接: http://acm.nyist.net/JudgeOnline/problem.php?pid=1248 描述 神秘的海洋,惊险的探险之路,打捞海底宝藏,激烈的海战,海盗劫富等等.加勒比 ...
- POJ 3268 Silver Cow Party (最短路径)
POJ 3268 Silver Cow Party (最短路径) Description One cow from each of N farms (1 ≤ N ≤ 1000) convenientl ...
- 【lightoj-1002】Country Roads(dijkstra变形)
light1002:传送门 [题目大意] n个点m条边,给一个源点,找出源点到其他点的‘最短路’ 定义:找出每条通路中最大的cost,这些最大的cost中找出一个最小的即为‘最短路’,dijkstra ...
- POJ 3268 Silver Cow Party (双向dijkstra)
题目链接:http://poj.org/problem?id=3268 Silver Cow Party Time Limit: 2000MS Memory Limit: 65536K Total ...
随机推荐
- C语言 内存管理(转)
转自 https://blog.csdn.net/u011616739/article/details/61621815 C语言 内存管理 1.内存分区 C源代码进过预处理.编译.汇编和链接4步生成 ...
- 前端面试题整理—React篇
1.说一下React React是Facebook 开发的前端JavaScript库 V层:react并不是完整的MVC框架,而是MVC中的C层 虚拟DOM:react引入虚拟DOM,每当数据变化通过 ...
- 配置rpm包安装的jdk环境变量
最近在搭建james邮件服务的时候,由于这个服务是用Java开发的,之前这台服务器跑过tomcat服务,故有Java环境,就没在意有无配置环境变量,但在启动james的时候报没有配置环境变量: 那么问 ...
- IntelliJ IDEA 2018最新版注册码激活方法
一.首先点击intellij idea 2018 二.选择激活码 三.输入以下激活码intellij idea 2018 最新版本 注册激活码 **************************** ...
- [译]Ocelot - Rate Limiting
原文 Ocelot支持对上游做访问限流,这样就可以保证下游不要负载太大了. 如果要启用访问限流,需要做如下配置: "RateLimitOptions": { "Clien ...
- Lucene的中文分词器
1 什么是中文分词器 学过英文的都知道,英文是以单词为单位的,单词与单词之间以空格或者逗号句号隔开. 而中文的语义比较特殊,很难像英文那样,一个汉字一个汉字来划分. 所以需要一个能自动识别中文语义的分 ...
- 小程序git发布
微信小程序提交项目: 1.码云上创建一个项目 xiaochengxu 2.本地创建一个文件夹,然后在控制台使用 cd 文件夹名字 (将文件拉到控制台) 3.使用 git init 命令 ,初始化一个g ...
- The SetStack Computer UVA - 12096
题意:初始状态的栈内包含一个空集,对栈进行一下操作: PUSH:向栈内压入一个空集 DUP:复制栈顶,并压入栈内 UNION:将栈顶端两个集合出栈,并将两个元素的并集入栈 INTERSECT:将栈顶端 ...
- DBA_TABLES ALL_TABLES USER_TABLES
DBA_TABLES >= ALL_TABLES >= USER_TABLES DBA_TABLES意为DBA拥有的或可以访问的所有的关系表. ALL_TABLES意为某一用户拥有的或可以 ...
- iview 非 template/render 标签转换
在 非 template/render情形下使用 iview,发现除了官方的一些需要注意的点外,还有一些其他需要注意的,这里记录下,防踩坑: 官方说明: 在非 template/render 模式下( ...