POJ 3268 Silver Cow Party
来源:互联网 发布:专利流氓知乎 编辑:程序博客网 时间:2024/04/30 11:27
大意:不再赘述,牛牛们一定可以到达目的地,当然也可以走回去。
思路:建立正、反向图,使用spfa,Dijkstra,枚举最大值均可。
CODE:
#include <iostream>#include <cstring>#include <cstdio>#include <cstdlib> #include <queue>using namespace std;const int INF = 0x3f3f3f3f;const int MAXN = 1010;const int MAXM = 100010;struct Edge{int v, next, w;}edge[MAXM];int n, m, src;int cnt;int first[MAXN], d[MAXN], ans[MAXN];int su[MAXM], sv[MAXM], sw[MAXM];int MaxTime;inline void read_graph(int u, int v, int w){edge[cnt].v = v;edge[cnt].w = w;edge[cnt].next = first[u], first[u] = cnt++;}inline void init(){cnt = 0;MaxTime = 0;memset(first, -1, sizeof(first));}void spfa(int src){queue<int> q;bool inq[MAXN] = {0};for(int i = 1; i <= n; i++) d[i] = (i == src)? 0:INF;q.push(src);while(!q.empty()){int x = q.front(); q.pop();inq[x] = 0;for(int e = first[x]; e != -1; e = edge[e].next){int v = edge[e].v, w = edge[e].w;if(d[v] > d[x] + w){d[v] = d[x] + w;if(!inq[v]){inq[v] = 1;q.push(v);}}}}}void solve(){init();for(int i = 0; i < m; i++){scanf("%d%d%d", &su[i], &sv[i], &sw[i]);read_graph(su[i], sv[i], sw[i]);}spfa(src);for(int i = 1; i <= n; i++) ans[i] += d[i];init();for(int i = 0; i < m; i++) read_graph(sv[i], su[i], sw[i]);spfa(src);for(int i = 1; i <= n; i++){ans[i] += d[i];MaxTime = max(MaxTime, ans[i]);}printf("%d\n", MaxTime);}int main(){while(~scanf("%d%d%d", &n, &m, &src)){solve();}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
- 机器学习 cs229学习笔记1
- 英语能力直接决定在IT行业发展的高度
- AjaxPro怎么传对象参数
- 深入浅出Node.js(一):什么是Node.js
- 深入浅出Node.js(二):Node.js&NPM的安装与配置
- POJ 3268 Silver Cow Party
- 数字图像处理_真彩图转换灰度图_纯C
- java学习攻略
- 深入浅出Node.js(三):深入Node.js的模块机制
- POJ3087,Shuffle'm Up,有人说这是bfs...
- Holding Bin-Laden Captive!(母函数)
- 如何为WinForm程序打包
- 自适应滤波算法的回音消除的学习
- 深入浅出Node.js(四):Node.js的事件机制