本题链接 : http://poj.org/problem?id=3268

  题目大意:牛们要去聚会,输入N = 顶点数(牛场);M = 边(路)的数目; X = 终点 (聚会点)。问题:求来回时间的最大值。

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:

Line 1: Three space-separated integers, respectively: NM, and X 
Lines 2..M+1: Line i+1 describes road i with three space-separated integers: AiBi, and Ti. The described road runs from farm Ai to farm Bi, requiring Ti time units to traverse.

Output:

Line 1: One integer: the maximum of time any one cow must walk.
4 8 2
1 2 4
1 3 2
1 4 7
2 1 1
2 3 5
3 1 2
3 4 4
4 2 3

Sample Output:

10
 
 解题思路:因为本题是单向的,所以在做的时候可以做一个正向图和一个反向图,分别求解来回的时间,然后找和的最大值。

这里是我的代码:
 #include <cstring>
#include <iostream>
#define INF 9999999
using namespace std; bool used[];
int V, E;
const int maxn = ; void dijkstra (int s, int cost[][], int d[]) {
fill (d, d + V + , INF);
fill (used,used + V + ,false);
d[s] = ;
while (true) {
int v = -;
for (int u = ; u <= V; u++) {
if (!used[u] && (v == - || d[u] < d[v])) v = u;
}
if (v == -) break;
used[v] = true;
for (int u = ; u <= V; ++u) {
if (d[u] > d[v] + cost[v][u]) {
d[u] = d[v] + cost[v][u];
}
}
}
} int cost[maxn][maxn];
int rcost[maxn][maxn]; int main () {
int d[maxn];
int rd[maxn];
int x, y, w;
int sum[maxn];
int S;
cin >> V >> E >> S; for (int i = ;i <= V; ++i)
for (int j = ; j <= V; ++j)
rcost[i][j] = cost[i][j] = INF; for (int i = ; i < E; ++i) {
cin >> x >> y >> w;
rcost[y][x] = cost[x][y] = w;
} dijkstra(S, cost, d);//分别计算最短路径
dijkstra(S, rcost, rd); for (int i = ; i <= V; ++i)//求和
sum[i] = d[i] + rd[i]; int maxnum = sum[];
for (int i = ; i <= V; ++i)///找最大值
if (sum[i] > maxnum)
maxnum = sum[i]; cout << maxnum << endl; return ;
}

    欢迎码友评论,一起成长。

<poj - 3268> Silver Cow Party 牛のpart 最短路径问题的更多相关文章

  1. POJ 3268 Silver Cow Party (最短路径)

    POJ 3268 Silver Cow Party (最短路径) Description One cow from each of N farms (1 ≤ N ≤ 1000) convenientl ...

  2. POJ 3268 Silver Cow Party 最短路—dijkstra算法的优化。

    POJ 3268 Silver Cow Party Description One cow from each of N farms (1 ≤ N ≤ 1000) conveniently numbe ...

  3. POJ 3268 Silver Cow Party (双向dijkstra)

    题目链接:http://poj.org/problem?id=3268 Silver Cow Party Time Limit: 2000MS   Memory Limit: 65536K Total ...

  4. POJ 3268 Silver Cow Party 最短路

    原题链接:http://poj.org/problem?id=3268 Silver Cow Party Time Limit: 2000MS   Memory Limit: 65536K Total ...

  5. POJ 3268 Silver Cow Party 最短路径+矩阵转换

    Silver Cow Party Time Limit : 4000/2000ms (Java/Other)   Memory Limit : 131072/65536K (Java/Other) T ...

  6. POJ 3268 Silver Cow Party (Dijkstra)

    Silver Cow Party Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 13982   Accepted: 6307 ...

  7. POJ 3268——Silver Cow Party——————【最短路、Dijkstra、反向建图】

    Silver Cow Party Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Su ...

  8. 图论 ---- spfa + 链式向前星 ---- poj 3268 : Silver Cow Party

    Silver Cow Party Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 12674   Accepted: 5651 ...

  9. poj 3268 Silver Cow Party

                                                                                                       S ...

随机推荐

  1. jquery validate 验证

    JSP中引入 <link href="themes/gray/easyui.css" rel="stylesheet" type="text/c ...

  2. 【总结】AngularJs学习总结

    应项目的需要,一个月之前开始做WebComponents.Javascript MVC框架的技术调研,由于重点是想做组件化,所以就没有考虑Backbone(去年就小试牛刀,太难用了)及其他的mvc框架 ...

  3. 数模学习笔记(五)——BP神经网络

    1.BP神经网络是一种前馈型网络(各神经元接受前一层的输入,并输出给下一层,没有反馈),分为input层,hide层,output层 2.BP神经网络的步骤: 1)创建一个神经网络:newff a.训 ...

  4. javascript ajax 脚本跨域调用全解析

    javascript ajax 脚本跨域调用全解析 今天终于有点时间研究了一下javsscript ajax 脚本跨域调用的问题,先在网上随便搜了一下找到一些解决的办法,但是都比较复杂.由是转到jqu ...

  5. python 中文字数统计/分词

    因为想把一段文字分词,所以,需要明确一定的词语关系. 在网上随便下载了一篇中文小说.随便的txt小说,就1mb多.要数数这1mb多的中文到底有多少字,多少分词,这些分词的词性是什么样的. 这里是思路 ...

  6. mysql 建表 AUTO_INCREMENT , 数据类型 VARCHAR

    建表: 原帖地址: http://blog.sina.com.cn/s/blog_5da3d5c50100bjh0.html MySQL AUTO_INCREMENT 简介 (2009-01-02 1 ...

  7. hdu 4467 Graph

    P. T. Tigris is a student currently studying graph theory. One day, when he was studying hard, GS ap ...

  8. 用curl自动登录HTTPS站点

    前文http://blog.csdn.net/sheismylife/article/details/9237925 演示了如何手动的通过运行curl命令登录HTTPS站点,然后获取cookie, 再 ...

  9. ADO.NET—两种连接模式

    一.ADO.NET简介 ADO.NET的名称起源于ADO(ActiveX Data Objects),这是一个广泛的类组,用于在以往的Microsoft技术中访问数据.用来访问数据库,.NET环境下首 ...

  10. php最新学习-----文件的操作

    一.文件:文件和目录 (1)判断文件的类型用:filetype() filetype("文件路径+文件名") //判断文件的类型 例如:我这里查找的的上一级目录中的json文件,输 ...