poj 3268 Silver Cow Party
来源:互联网 发布:钉钉管理员能看到数据 编辑:程序博客网 时间:2024/06/06 13:03
Memory Limit: 65536KTotal Submissions: 16277
Accepted: 7450
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
<span style="font-size:18px;">void tra(){ int temp; for(int i=1;i<=n;i++) for(int j=1;j<=i;j++) //注意是就j<=i { temp=map[i][j]; map[i][j]=map[j][i]; map[j][i]=temp; }} </span>下面是总的代码:
<span style="font-size:18px;">#include<cstdio>#include <iostream>#include <cstdio>#include <cstring>#include <cstdlib>#include <cmath>#include <vector>#include <queue>#include <algorithm>#include <set>using namespace std;#define MM(a) memset(a,0,sizeof(a))typedef long long LL;typedef unsigned long long ULL;const int maxn = 1e3+5;const int mod = 1000000007;const double eps = 1e-10;const int inf = 0x3f3f3f3f;int map[1005][1005],dist[1005],used[1005],ans[1005];int n,m,s;void init(){ memset(map,inf,sizeof(map)); memset(ans,0,sizeof(ans)); for(int i=1;i<=n;i++) map[i][i]=0;}int min(int a ,int b){ return a>b?b:a;}void tra(){ int temp; for(int i=1;i<=n;i++) for(int j=1;j<=i;j++) { temp=map[i][j]; map[i][j]=map[j][i]; map[j][i]=temp; }} //数组反向void dijkstra(){ memset(used,0,sizeof(used)); memset(dist,inf,sizeof(dist)); dist[s]=0; while(1) { int u=0,minn=inf; for(int i=1;i<=n;i++) if(!used[i]&&dist[i]<minn) { u=i; minn=dist[i]; } if(u==0) break; used[u]=1; for(int i=1;i<=n;i++) if(!used[i]&&dist[i]>dist[u]+map[u][i]) dist[i]=dist[u]+map[u][i]; } for(int i=1;i<=n;i++) ans[i]+=dist[i];}int main(){ while(~scanf("%d %d %d",&n,&m,&s)) { init(); int x,y,c; for(int i=1;i<=m;i++) { scanf("%d %d %d",&x,&y,&c); map[x][y]=c; } dijkstra(); tra(); dijkstra(); int maxn=0; for(int i=1;i<=n;i++) if(ans[i]>maxn) maxn=ans[i]; printf("%d\n",maxn); } return 0;}</span>
- 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
- 第十二课 定位画图---坐标
- js对象或类的方法设计模式解读
- VirtualBox 删掉虚拟镜像重新安装失败
- mac 上显示 . 开头的隐藏文件
- 看懂执行计划 顺序
- poj 3268 Silver Cow Party
- 如何用 React Native 创建一个iOS APP?
- Java并发编程:并发基础概念
- 关于hive环境搭建
- 怎样修改tomcat的文件上传限制
- 大学就是修心
- 为什么会有article和aside不同的标签
- 在myeclipse中 移动多行代码
- python学习手册 简记