poj 3268 Silver Cow Party
来源:互联网 发布:好的爸爸网络用语 编辑:程序博客网 时间:2024/04/30 11:18
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>int INF=10000000;int n,maps1[1010][1010],dis1[1010],maps2[1010][1010],dis2[1010];void adijk(int maps[][1010],int *dis)//因为都是一样的算法。所以传参数处理了{ int i,j,p,mi,visit[1010]; memset(visit,0,sizeof visit); for(i=1; i<=n; i++) { mi=INF; p=-1; for(j=1; j<=n; j++) if(!visit[j]&&dis[j]<=mi) mi=dis[j],p=j; if(p==-1)//如果没找到最小值直接返回 return ; visit[p]=1; for(j=1; j<=n; j++) if(!visit[j]&&dis[p]+maps[p][j]<dis[j]) dis[j]=dis[p]+maps[p][j]; }}int main(){ int m,x,i,j,a,b,t,ma; scanf("%d%d%d",&n,&m,&x); for(i=1; i<=n; i++) { dis1[i]=dis2[i]=INF; for(j=1; j<=n; j++) { if(i==j) maps1[i][j]=maps2[i][j]=0; else maps1[i][j]=maps2[i][j]=INF; } } for(i=1; i<=m; i++) { scanf("%d%d%d",&a,&b,&t); if(t<maps1[a][b]) maps1[a][b]=maps2[b][a]=t;//分别记录道路信息 } dis1[x]=dis2[x]=0; adijk(maps1,dis1); adijk(maps2,dis2); ma=-1; for(i=1; i<=n; i++) { if(dis1[i]+dis2[i]>ma) ma=dis1[i]+dis2[i]; } printf("%d\n",ma); return 0;}
- 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
- 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
- 深入MFC中WM_COMMAND命令消息的传递
- jQuery-ui插件datepicker的参数使用详解
- Eclipse 快捷键Alt+/提示“No Default Proposals”解决办法 .
- ndroid ListView详解
- WM_COMMAND & WM_SYSCOMMAND
- poj 3268 Silver Cow Party
- dubbo 学习笔记 -- consumer端
- CodeIgniter 核心代码阅读-输入数据处理文件Input.php
- Java对象的生命周期-内存分配、回收内存
- 详解Wavedev2模式的音频驱动
- svn: error while loading shared libraries: libsvn_client-1.so.0
- oracle使用cursor动态更新线上初始化数据
- Ensemble连接oracle数据库的3种方法
- #小练习 HTMLParser