POJ 3268 D-Silver Cow Party
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
代码:
#include <iostream>
#include <string.h>
#include <stdio.h>
using namespace std;
#define MAXV 1010
#define inf 0x3f3f3f3fint mp[MAXV][MAXV], d[MAXV], dback[MAXV];
bool vis[MAXV];
int n, m, x;int dijkstra(){int v, mi;for(int i = 1; i <= n; i ++) {vis[i] = 0;d[i] = mp[x][i];dback[i] = mp[i][x];}for(int i = 1; i <= n; i ++){mi = inf;for(int j = 1; j <= n; j ++)if(!vis[j] && d[j] < mi) {v = j;mi = d[j];}vis[v] = 1;for(int j = 1; j <= n; j ++) {if(!vis[j] && mp[v][j] + d[v] < d[j])d[j] = mp[v][j] + d[v];}}memset(vis, 0, sizeof(vis));for(int i = 1; i <= n; i ++) {mi = inf;for(int j = 1; j <= n; j ++)if(!vis[j] && dback[j] < mi){v = j;mi = dback[j];}vis[v] = 1;for(int j = 1; j <= n; j ++){if(!vis[j] && mp[j][v] + dback[v] < dback[j])dback[j] = mp[j][v] + dback[v];}}mi = -1;for(int i = 1; i <= n; i ++) {if(d[i] + dback[i] > mi)mi = d[i] + dback[i];}return mi;
}int main(){int a, b, c;while(~scanf("%d%d%d", &n, &m, &x)){for(int i = 1; i <= n; i ++){for(int j = 1; j <= n; j ++)if(i != j) mp[i][j] = inf;else mp[i][j]=0;}for(int i = 1;i <= m; i ++){scanf("%d%d%d", &a, &b, &c);mp[a][b] = c;}printf("%d\n",dijkstra());}return 0;
}
转载于:https://www.cnblogs.com/zlrrrr/p/9879164.html
POJ 3268 D-Silver Cow Party相关推荐
- POJ 3268:Silver Cow Party 求单点的来回最短路径
Silver Cow Party Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 15989 Accepted: 7303 ...
- 【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 ...
- D - Silver Cow Party POJ - 3268
D - Silver Cow Party POJ - 3268 dijkstra 是 O(n2),堆优化一下, O(nlogn) 对每个点跑一次 dj, 取 max(dis(x->i)+dis( ...
- POJ 3268 Silver Cow Party (最短路径)
POJ 3268 Silver Cow Party (最短路径) Description One cow from each of N farms (1 ≤ N ≤ 1000) convenientl ...
- Silver Cow Party (POJ - 3268 )
Silver Cow Party (POJ - 3268 ) 这道题是我做的最短路专题里的一道题,但我还没做这个,结果比赛就出了,真是.......... 题目: One cow from each ...
- [POJ](3268)Silver Cow Party ---最短路径(图)
Silver Cow Party Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 23762 Accepted: 1085 ...
- POJ 3278 Catch That Cow
Catch That Cow Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 30924 Accepted: 9536 D ...
- POJ 3268 (dijkstra算法)
Silver Cow Party Description One cow from each of N farms (1 ≤ N ≤ 1000) conveniently numbered 1..N ...
- BFS POJ 3278 Catch That Cow
题目传送门 1 /* 2 BFS简单题:考虑x-1,x+1,x*2三种情况,bfs队列练练手 3 */ 4 #include <cstdio> 5 #include <iostrea ...
最新文章
- Redis键命令(查找键、判断键值是否存在、查看键值类型、删除键值、设置过期时间、查看键值有效时间)
- 据说腾讯的算法高手都是C++背景
- Javascript:字符串分割split()妙用
- VTK:PolyData之ColoredPoints
- python编程语言一览_编程语言学习:python有趣用法汇总
- 这一大波电子“艺术”图,美翻了!
- .NET | 多线程下的调用上下文 : CallContext
- YUM只下载软件不安装的设定
- HDU2178 猜数字【数学计算+水题】
- R语言重抽样与自助法
- spring @Transactional注解的使用和失效场景
- 自抗扰控制理论(一)ADRC的原理
- (2)香橙派+apache2与php+天猫精灵=自建平台语音支持--香橙派操作系统安装
- 从word中复制图片到网页编辑器中
- 如何用计算机做样本抽样,抽样设计和样本抽选.doc
- 什么?HomeKit、米家、Aqara等生态也能通过智汀与天猫精灵生态联动?
- python和excel数据分析有什么区别_用Excel、SQL、Python做数据分析有何不同?
- 报错笔记-[error] 1615#0: *14 open() “/usr/local/nginx/html/course/zk.jpg“ failed (2: No such file or dir
- Android端实现多人音视频聊天应用(一)
- [句型] 二十六、特殊疑问句 3