Time Limit: 2000MS   Memory Limit: 65536K
Total Submissions: 19226   Accepted: 8775

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.

Sample Input

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

Hint

Cow 4 proceeds directly to the party (3 units) and returns via farms 1 and 3 (7 units), for a total of 10 time units.
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int map[][],w[][];
int dis[],Team[];
bool exist[];
int n,m,t; // exist 为 true 则不可进队
void SPFA(int s)
{
int head=,tail=,k=;
Team[head]=s,exist[s]=true;dis[s]=;
while(head<tail)
{
k=Team[head];
exist[k]=false;
for(int i=;i<=n;i++)
{
if((map[k][i]>)&&(dis[i]>dis[k]+map[k][i]))
{
dis[i]=map[k][i]+dis[k];
if(exist[i]==false)
{
Team[tail++]=i;
exist[i]=true;
}
}
}
head++;
}
}
int main()
{
cin>>n>>m>>t;
memset(map,0x3f,sizeof map );
memset(w,0x3f,sizeof w );
memset(dis,0x3f,sizeof dis );
for(int i=;i<=m;i++)
{
int x,y,z;
cin>>x>>y>>z;
map[x][y]=z;
w[x][y]=z;
}
SPFA(t);// 从起点开始到其他每个点找一遍最短路
for(int k=;k<=n;k++)
{
for(int i=;i<=n;i++)
{
for(int j=;j<=n;j++)
{
if(w[i][j]>w[i][k]+w[k][j])
w[i][j]=w[i][k]+w[k][j];
}
}
}
int max;
for(int i=;i<=n;i++)
{
if((i==)||(dis[i]+w[i][t]>max))
max=dis[i]+w[i][t]; }
printf("%d",max);
return ;
}

思路:一遍SPFA求出起点到其他所有点的最短路,一遍Floyed求出所有点到起点的最短路,两者相加,和最大者即为anwser...

BZOJ 1631==USACO 2007== POJ 3268 Cow Party奶牛派对的更多相关文章

  1. 【BZOJ】【1046】/【POJ】【3613】【USACO 2007 Nov】Cow Relays 奶牛接力跑

    倍增+Floyd 题解:http://www.cnblogs.com/lmnx/archive/2012/05/03/2481217.html 神题啊= =Floyd真是博大精深…… 题目大意为求S到 ...

  2. BZOJ 1631 Usaco 2007 Feb. Cow Party

    [题解] 最短路裸题.. 本题要求出每个点到终点走最短路来回的距离,因此我们先跑一遍最短路得出每个点到终点的最短距离,然后把边反向再跑一遍最短路,两次结果之和即是答案. #include<cst ...

  3. BZOJ 1641 USACO 2007 Nov. Cow Hurdles 奶牛跨栏

    [题解] 弗洛伊德.更新距离的时候把$f[i][j]=min(f[i][j],f[i][k]+f[k][j])$改为$f[i][j]=min(f[i][j],max(f[i][k],f[k][j])) ...

  4. [BZOJ 1647][USACO 2007 Open] Fliptile 翻格子游戏

    1647: [Usaco2007 Open]Fliptile 翻格子游戏 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 702  Solved: 281[ ...

  5. 【BZOJ】1654: [Usaco2006 Jan]The Cow Prom 奶牛舞会(tarjan)

    http://www.lydsy.com/JudgeOnline/problem.php?id=1654 请不要被这句话误导..“ 如果两只成功跳圆舞的奶牛有绳索相连,那她们可以同属一个组合.” 这句 ...

  6. POJ 2184 Cow Exhibition 奶牛展(01背包,变形)

    题意:有只奶牛要证明奶牛不笨,所以要带一些奶牛伙伴去证明自己.牛有智商和幽默感,两者可为负的(难在这),要求所有牛的智商和之 / 幽默感之和都不为负.求两者之和的最大值. 思路:每只牛可以带或不带上, ...

  7. POJ 3268 Silver Cow Party 最短路

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

  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 (最短路径)

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

随机推荐

  1. 用户环境配置文件/etc/profile

    当用户在登录界面正确地输入用户名和密码后,系统就开始为用户构建一个可以使用的用户环境.用户环境包括用户使用的环境变量.快捷键设置及命令别名等.这些设置大多是通过运行全局用户配置文件/etc/profi ...

  2. C++面试题:list和vector有什么区别?

    原文:http://genwoxuevc.blog.51cto.com/1852984/503337 C++面试题:list和vector有什么区别?考点:理解list和vector的区别出现频率:★ ...

  3. C# unix时间戳转换

    场景:由于业务需要和java 开发的xxx系统对接日志,xxx系统中用“1465195479100” 来表示时间,C# 里面需要转换做一下逻辑处理,见代码段. C#获取的unix时间戳是10位,原因是 ...

  4. 创建对象_工厂方法(Factory Method)模式 与 静态工厂方法

      工厂方法模式:   定义:为创建对象定义一个接口,让子类决定实例化哪个类.工厂方法让一个类的实例化延迟至子类.   应用场景: 客户类不关心使用哪个具体类,只关心该接口所提供的功能: 创建过程比较 ...

  5. ProcMon启用调试符

    1.设置 _NT_SYMBOL_PATH 如果在 _NT_SYMBOL_PATH 环境变量中提供了正确的?symsrv?语法,则常见的 Mircoroft 调试工具将使用 SymSrv 技术.这些工具 ...

  6. ARC 和 MRC 小结

    ARC 和 MRC 内存管理 从 MRC—>ARC 就是将内存管理部分,从开发者的函数中转移到函数外部的runtime 中.由于 runtime 的开发简单,逻辑层次高,所以 runtime 的 ...

  7. 【转】ViewGroup的onMeasure和onLayout分析

    ViewGroup的onMeasure和onLayout分析 一个Viewgroup基本的继承类格式如下: 1 import android.content.Context; 2 import and ...

  8. web前端开发(6)

    为了避免全局变量泛滥导致冲突,最简单有效的办法是用匿名函数将脚本包起来,让变量的作用域控制在函数之内.

  9. javaweb学习总结二十五(response对象的用法一)

    一:Reponse对象的概念 当客户端发送http请求时,服务器端会对每一次请求,创建request对象和response对象. response对象包括三个部分:响应头.响应状态码以及响应体 二:r ...

  10. CF Two Substrings

    Two Substrings time limit per test 2 seconds memory limit per test 256 megabytes input standard inpu ...