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. 百度UEditor组件出现Parameters: Invalid chunk &#39;&#39; ignored警告的分析

    使用百度UEditor在线编辑器组件时,出现Parameters: Invalid chunk '' ignored的警告,之前的项目使用却没有.两个项目的环境应该是一样的. 没有时间去对照两项目使用 ...

  2. cocos2d-x jsbinding 在线更新策略设计

    在线更新是用脚本编写游戏逻辑的特有功能,由于脚本语言是边解释边编译的特性,使得游戏在运行的时候可以通过下载最新的脚本来执行游戏逻辑.在不修改Native接口的情况下,在线更新每次更新只需要下载一个(5 ...

  3. innobackupex 备份实验

    [root@localhost ~]# xtrabackup -v xtrabackup version based Linux (x86_64) (revision id: 45cda89) [ro ...

  4. 标准库 - fmt/format.go 解读

    // Copyright 2009 The Go Authors. All rights reserved. // Use of this source code is governed by a B ...

  5. Deepin Linux 安装JDK

    最近在自己的笔记本上安装了Deepin Linux,虽然使用过程中发现一些bugs,但是总体感觉还不错,准备把她作为开发系统使用.系统自带的JDK是Open JDK,但是在做JAVA开发的时候通常需要 ...

  6. poll机制分析

    更多文档:http://pan.baidu.com/s/1sjzzlDF linux poll/select用法及在字符驱动中的简单实现 1.poll和select 使用非阻塞I/O 的应用程序常常使 ...

  7. maven添加jetty插件

    pom.xml中增加jetty的配置 <properties> <jetty-version>8.1.13.v20130916</jetty-version> &l ...

  8. spring 学习总结

    前几天,一直在学spring,然后又学习spring mvc ,再回过头去看spring,本来不是特别熟悉,竟然几乎全部忘记了.于是,立刻写这篇博客来总结一下.这是我写的其中一个程序,大概的逻辑流程. ...

  9. 每天一道面试题(2):实现strncpy

    目录 0. 为何要写strncpy? 1. 源码及测试结果 2. 面试注意事项 3. 小结

  10. input[type='submit']input[type='button']button等按钮在低版本的IE下面,去掉黑色边框的问题

    今天做一个tabs效果的时候,发现上面的button在低版本下会出现黑色的边框,很难看,于是我整理了下几个去掉黑色边框的办法: 1.在button的外层嵌套一个div,设置button的border: ...