POJ Silver Cow Party
来源:互联网 发布:员工工作证制作软件 编辑:程序博客网 时间:2024/05/21 11:06
https://cn.vjudge.net/problem/11757/origin
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 21 2 41 3 21 4 72 1 12 3 53 1 23 4 44 2 3
Sample Output
10
Hint
Source
#include<stdio.h>#include<string.h>#define INF 0x3f3f3f3f#define MAX1 1000+10int book[MAX1],map[MAX1][MAX1],vis1[MAX1];int dis[101000][3],n,m,a,vis[MAX1];void F(){ for(int i=0; i<m; i++) { int x=dis[i][0]; int y=dis[i][1]; int z=dis[i][2]; if(z<map[y][x]) map[y][x]=z; } return ;}void djikrsta(){ int i,j,MAX2,u; memset(book,0,sizeof(book)); memset(vis,INF,sizeof(vis)); for(i=1; i<=n; i++) vis[i]=map[a][i]; book[a]=1; for(i=1; i<=n; i++) { MAX2=INF ,u=i; for(j=1; j<=n; j++) if(!book[j]&&vis[j]<MAX2) { MAX2=vis[j]; u=j; } book[u]=1; for(j=1; j<=n; j++) if(!book[j]&&vis[j]>map[u][j]+vis[u]) vis[j]=map[u][j]+vis[u]; }}void huan(){ for(int i=1; i<=n; i++) vis1[i]=vis[i];}void chushihua(){ for(int i=1; i<=n; i++) for(int j=1; j<=n; j++) if(i==j) map[i][j]=0; else map[i][j]=INF;}int main(){ while(~scanf("%d %d %d",&n,&m,&a)) { int i,j,max3=0,x,y,z; chushihua(); for(i=0; i<m; i++) { scanf("%d %d %d",&dis[i][0],&dis[i][1],&dis[i][2]); x=dis[i][0]; y=dis[i][1]; z=dis[i][2]; if(z<map[x][y]) map[x][y]=z; } djikrsta(); huan(); chushihua(); F(); djikrsta(); for(i=1; i<=n; i++) if(vis[i]+vis1[i]>max3) max3=vis[i]+vis1[i]; printf("%d\n",max3); } return 0;}
- poj Silver Cow Party
- poj Silver Cow Party
- Silver Cow Party POJ
- Silver Cow Party POJ
- Silver Cow Party POJ
- Silver Cow Party POJ
- POJ Silver Cow Party
- Silver Cow Party POJ
- Silver Cow Party POJ
- poj 3268 Silver Cow Party
- POJ 3268 Silver Cow Party
- poj 3268 Silver Cow Party
- POJ 3268 Silver Cow Party
- POJ 3268 Silver Cow Party
- POJ-3268-Silver Cow Party
- poj 3268 Silver Cow Party
- poj 3268 Silver Cow Party
- POJ-3268-Silver Cow Party
- java
- Xcode6为什么干掉pch(Precompile Prefix Header)&如何添加pch文件
- bzoj 3876 [Ahoi2014]支线剧情
- ubuntu+github 项目托管 更新
- JSTL标签库
- POJ Silver Cow Party
- 加载布局时,未清空父布局
- 树莓派上面安装配置teamviewer
- windows下搭建virtualenvwrapper虚拟环境
- C++算法学习——数据结构——链表(2)
- 1003. 我要通过!(20)
- python爬虫之re正则表达式库
- CAEmitterLayer 详解
- 链表基础(C语言实现)