本题链接 : 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. ASP.NET MVC 用户登录Login

    ASP.NET MVC 用户登录Login一.先来看个框架例子:(这个是网上收集到的)  第一步:创建一个类库ClassLibrary831.            第二步:编写一个类实现IHttpM ...

  2. Web API CSRF保护实现

    Web API CSRF保护实现 这次自己实现了类似jQuery中ajax调用的方法,并且针对RESTFul进行了改造和集成,实现的A2D AJAX接口如下: $.ajax.RESTFulGetCol ...

  3. Jquery EasyUI tabs处理

    一 获取选中的 Tab 1.   // 获取选中的 tab panel 和它的 tab 对象 2.  var pp = $('#tt').tabs('getSelected'); 3.  var ta ...

  4. Excel 开发概述

    浅谈Excel开发:一 Excel 开发概述 做Office相关的开发工作快一年多了,在这一年多里,在插件的开发中遇到了各种各样的问题和困难,还好同事们都很厉害,在和他们的交流讨论中学到了很多的知识. ...

  5. Visual Studio 2012设置Jquery/Javascript智能提示

    Visual Studio 2012设置Jquery/Javascript智能提示 在Visual Studio 2008 Visual Studio 2010中微软已经开始支持jquery/java ...

  6. hdu1263 水果(结构体排序)

    Problem Description 夏天来了~~好开心啊,呵呵,好多好多水果~~ Joe经营着一个不大的水果店.他认为生存之道就是经营最受顾客欢迎的水果.现在他想要一份水果销售情况的明细表,这样J ...

  7. UITableView的常用方法与示例

    实例方法 dequeueReusableCellWithIdentifier: 初始化一个指定重用标识符的UITableCell对象 两个协议 UITableViewDataSource tableV ...

  8. sql编程 && 存储过程

    sql  结构化查询语言      是一种编程语言   用于管理数据库的编程语言      元素:     数据      数据类型         变量的数据类型  就是字段的数据类型      变 ...

  9. 使用LR11录制手机脚本

    要使用Loadrunner11录制手机脚本,需要先搭建好测试环境:  能够正常使用的LoadRunner11:  安装一个LR11的补丁包,用于手机录制:  pc端和手机端的网络在同一个网段.  ...

  10. tabindex属性

    1. tabindex的用法: 可以设置tab键在控件中的移动顺序. 以下元素支持tabindex属性:<a> <input> <textarea> <are ...