博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
POJ-3268-D - Silver Cow Party(折返最短路)
阅读量:6934 次
发布时间:2019-06-27

本文共 1701 字,大约阅读时间需要 5 分钟。

题目描述:

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

Line 1: Three space-separated integers, respectively: N, M, and X
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
Line 1: One integer: the maximum of time any one cow must walk.
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
Cow 4 proceeds directly to the party (3 units) and returns via farms 1 and 3 (7 units), for a total of 10 time units.


思路:分别求每个点去x和从x走到每个点的最短路,最后分别求和取最大值即可。用到了两次dijk算法。多点到一点的最短路,就是把距离矩阵转置(所有路换方向),然后就变成了单点到多点的最短路。

坑点:max()和min()函数是<algorithm>里的。


1 #include
2 #include
3 #include
4 #define Inf 0x3f3f3f3f 5 using namespace std; 6 int G[1005][1005],mark[1005],dis1[1005],dis2[1005]; 7 int m,n,x; 8 9 void Getmap(){10 int u,v,w;11 memset(G,Inf,sizeof(G));12 for(int i=1;i<=n;i++)13 G[i][i]=0;14 for(int i=0;i

 

转载于:https://www.cnblogs.com/yzhhh/p/9978443.html

你可能感兴趣的文章
PHP date函数参数详解
查看>>
DDoS攻击走向应用层
查看>>
智领新时代 慧享新生活 —— CITE2018新闻发布会在北京召开
查看>>
探秘区块链 - 头条新闻
查看>>
区块链应用 | 用区块链颠覆视频直播,与视频卡顿、缓冲说再见!
查看>>
Python的pyroute2网络模块
查看>>
从零开始学Win32平台缓冲区溢出(Part1)
查看>>
一朵为员工赋能的“美”云
查看>>
PostgreSQL Oracle 兼容性之 - PL/SQL DETERMINISTIC 与PG函数稳定性(immutable, stable, volatile)...
查看>>
万万想不到,你是这样的“闲鱼”!
查看>>
Logstash 推送告警到阿里钉钉(Dingtalk)
查看>>
软银机器人Pepper上岗必胜客,顾客可通过机器人预订披萨
查看>>
较主流的消息队列的比较与选型
查看>>
SQL SERVER全面优化-------写出好语句是习惯
查看>>
安卓 AsyncHttpClient - “Content-Type not allowed!”
查看>>
samba
查看>>
虚拟机克隆步骤
查看>>
ListView使用技巧
查看>>
MySQL共享存储主备模式利用Keepalived实现双机高可用
查看>>
作为AI的“辅助大臣”,区块链的前途不可限量
查看>>