【POJ3268】【Silver Cow Party】【反向dij】【sizeof失效】
来源:互联网 发布:征途服务端linux版 编辑:程序博客网 时间:2024/06/09 21:11
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
sizeof() 失效
#include <iostream>#include <cstring>#include <cmath>#include <queue>#include <stack>#include <list>#include <map>#include <set>#include <string>#include <cstdlib>#include <cstdio>#include <algorithm>using namespace std; int N,M,X;int g[1010][1010];int d1[1010];int d2[1010];bool vis[1010];const int INF = 0x7fffffff/100;void dij(int g[1010][1010],int d[1010]){rep(i,0,N) d[i] = INF;memset(vis,0,sizeof(vis));d[X] = 0;rep(i,0,N-1){int dmin = INF;int p = -1;rep(j,0,N) {if(!vis[j] && d[j] < dmin){dmin = d[j];p = j;}}vis[p] = true;rep(j,0,N) {if(!vis[j] && d[j] > d[p] + g[p][j]){d[j] = d[p] + g[p][j];}}}}void travs(){rep(i,0,N) rep(j,i,N) {int tmp = g[i][j];g[i][j] = g[j][i];g[j][i] = tmp;}}int main(){ while(scanf("%d%d%d",&N,&M,&X) != EOF){X --;rep(i,0,N) rep(j,0,N) g[i][j] = INF;rep(i,0,M) {int u,v,w;scanf("%d%d%d",&u,&v,&w);u--,v--;g[u][v] = min(g[u][v],w);}dij(g,d1);travs();dij(g,d2);int maxs = -1;for(int i=0;i<N;i++){if(maxs < d1[i] + d2[i]){maxs = d1[i] + d2[i];}}printf("%d\n",maxs);} return 0;}
- 【POJ3268】【Silver Cow Party】【反向dij】【sizeof失效】
- POJ3268 Silver Cow Party DIJ最短路
- 【POJ3268】Silver Cow Party(dij/矩阵转置)
- POJ3268:Silver Cow Party
- poj3268 - Silver Cow Party
- POJ3268 Silver Cow Party
- POJ3268 Silver Cow Party
- POJ3268 Silver Cow Party
- poj3268-Silver Cow Party
- POJ3268-Silver Cow Party
- poj3268 Silver Cow Party
- poj3268 -- Silver Cow Party
- POJ3268 Silver Cow Party
- POJ3268 Silver Cow Party
- POJ3268 Silver Cow Party
- POJ3268-Silver Cow Party
- poj3268-Silver Cow Party
- POJ3268—Silver Cow Party(反向最短路)
- 第四周第二天
- 【ODPS】本地数据库数据批量上传到ODPS中
- Fragment 实现tab页卡切换并保存界面状态,动态添加Fragment
- Android学习0818<二>(界面布局)
- Java关键字static、final使用小结
- 【POJ3268】【Silver Cow Party】【反向dij】【sizeof失效】
- greenDAO学习分享总结
- 洛谷1001 A+B Problem
- 时间转换
- java垃圾回收之Minor GC和Major GC
- Cygwin
- 编码解码过程中的信息丢失现象
- HDU 1017.A Mathematical Curiosity【细节及转换】【8月18】
- hdu2094(水题)