poj 3268--Silver Cow Party
来源:互联网 发布:淘宝服装手机拍摄技巧 编辑:程序博客网 时间:2024/04/30 09:34
一个N个顶点,M条边的有向图,求从其他点往返X点的最短路的最大值。
http://poj.org/problem?id=3268
这道题居然WA了一晚上。。。 X﹏X,最后抱着试一试的心态,我把数组开大了。。居然就过了。。。居然。。。⊙﹏⊙b。。。
两次spfa,先求一次,把图反向在求一次,两次路径加和,输出最大值,就完了。。。。。
#include <queue>#include <stack>#include <cstdio>#include <cstring>#include <algorithm>using namespace std;struct node{ int v, w, next;}edge[1000000 + 10];int n, m, x, d[10010], time[10010], head[10010], cnt, u[10010], v[10010], w[10010];bool used[10010];void addedge(int u, int v, int w){ edge[cnt].v = v; edge[cnt].w = w; edge[cnt].next = head[u]; head[u] = cnt++;}void spfa(int s){ memset(used, 0, sizeof(used)); for(int i=0; i<=n; i++) d[i] = 0x7fffffff; d[s] = 0; queue<int> Q; while(!Q.empty()) Q.pop(); Q.push(s); while(!Q.empty()){ int now = Q.front(); Q.pop(); used[now] = false; for(int i=head[now]; ~i; i=edge[i].next){ int v = edge[i].v, w = edge[i].w; if(d[v] > d[now] + w){ d[v] = d[now] + w; if(!used[v]) { used[v] = true; Q.push(v); } } } } for(int i=1; i<=n; i++) time[i] += d[i];}int main(){ scanf("%d%d%d", &n, &m, &x); memset(head, -1, sizeof(head)); cnt = 0; memset(time, 0, sizeof(time)); for(int i=0; i<m; i++){ scanf("%d%d%d", &u[i], &v[i], &w[i]); addedge(u[i], v[i], w[i]); } spfa(x); memset(head, -1, sizeof(head)); cnt = 0; for(int i=0; i<m; i++) addedge(v[i], u[i], w[i]); spfa(x); int ans = 0; for(int i=1; i<=n; i++){ ans = max(ans, time[i]); } printf("%d\n", ans); return 0;}
0 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
- 自学Linux命令的四种方法
- DEV Gridcontrol 格式化显示数据
- 使用plist(属性列表)实现数据读写
- 深入理解Java中为什么内部类可以访问外部类的成员
- Ganymed SSH-2 for Java
- poj 3268--Silver Cow Party
- HDU 3397 Sequence operation
- C++中的各种小细节(二)
- 安装nginx
- 外卖网开源项目
- LeetCode - Remove Duplicates from Sorted Array II
- CPU 硬盘性能到底相差多少
- 杂合记录--OA
- Reverse Integer