博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
POJ-3268-Silver Cow Party
阅读量:6615 次
发布时间:2019-06-24

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

问题描述

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 ≤ XN). 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?

输入

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.

输出

Line 1: One integer: the maximum of time any one cow must walk.

样例输入

4 8 21 2 41 3 21 4 72 1 12 3 53 1 23 4 44 2 3

样例输出

10

提示

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.
 
//求所有最小路径中的最大值
//从起点到终点,从终点到起点的和的最小路径
从终点到起点计算时,建立另外一个反向图,把终点设为起点
注意vis 在算第二个最短路径时要重新初始化!
1 #include 
2 #include
3 #include
4 using namespace std; 5 const int N=1100; 6 const int inf=1<<29; 7 int u,v,m,n,q,c; 8 int d1[N],d2[N],w1[N][N],w2[N][N],vis[N]; 9 void dij1(int st) 10 { 11 for(int i=1;i<=n;i++) 12 { 13 d1[i]=inf; 14 } 15 d1[st]=0; 16 for(int i=1;i<=n;i++) 17 { 18 int now=inf; 19 int x; 20 for(int j=1;j<=n;j++) 21 { 22 if(!vis[j]&&now>d1[j]) 23 { 24 now=d1[j]; 25 x=j; 26 } 27 } 28 vis[x]=1; 29 for(int j=1;j<=n;j++) 30 { 31 if(!vis[j]&&d1[j]>d1[x]+w1[x][j]) 32 { 33 d1[j]=d1[x]+w1[x][j]; 34 } 35 } 36 } 37 } 38 void dij2(int st) 39 { 40 memset(vis,0,sizeof(vis)); 41 for(int i=1;i<=n;i++) 42 { 43 d2[i]=inf; 44 } 45 d2[st]=0; 46 for(int i=1;i<=n;i++) 47 { 48 int now=inf; 49 int x; 50 for(int j=1;j<=n;j++) 51 { 52 if(!vis[j]&&now>d2[j]) 53 { 54 now=d2[j]; 55 x=j; 56 } 57 } 58 vis[x]=1; 59 for(int j=1;j<=n;j++) 60 { 61 if(!vis[j]&&d2[j]>d2[x]+w2[x][j]) 62 { 63 d2[j]=d2[x]+w2[x][j]; 64 } 65 } 66 } 67 } 68 int main() 69 { 70 while(scanf("%d%d%d",&n,&m,&q)!=EOF) 71 { 72 memset(vis,0,sizeof(vis)); 73 for(int i=1; i<=n; i++) 74 { 75 for(int j=1; j<=n; j++) 76 { 77 w1[i][j]=inf; 78 w2[i][j]=inf; 79 } 80 } 81 for(int i=1; i<=m; i++) 82 { 83 scanf("%d%d%d",&u,&v,&c); 84 if(c

 

转载于:https://www.cnblogs.com/tianmin123/p/4790708.html

你可能感兴趣的文章
组策略18招
查看>>
关于Android中的数据存储
查看>>
Tomcat配置日志生产功能
查看>>
js的自执行函数
查看>>
移植Qt与Tslib到X210开发板的体会
查看>>
Nginx + webpy 和FastCGI搭建webpy环境
查看>>
new static 跟 new self 区别
查看>>
PLSQL Develope连接oracle数据库配置
查看>>
使用JdbcTemplate过程中使用到多个参数和like模糊
查看>>
解决eclipse中无法删除Tomcat服务器中的项目,报maven is required and cannot be removed from the server错误情况...
查看>>
修改页面JS 360浏览器
查看>>
尚学linux课程---3、linux网络说明
查看>>
Git 跟 GitHub 是什么关系?
查看>>
String.split()方法
查看>>
IE6下jQuery选中select的BUG
查看>>
Tensorflow在win10下的安装(CPU版本)
查看>>
嵌入式平台做深度学习算法,不可不重视的4件事
查看>>
一次优化记录
查看>>
如何调用一个数据完整的firefox浏览器
查看>>
cgroup代码浅析(2)
查看>>