题目大意:

在一个农场里面所有的牛都会来参加大牛举办的派对,不过农场的路都是单向的,而且每头牛都喜欢都最短的路程,那么问题来了,求出来来回花费时间最多的那头牛所用的时间。。。
/////////////////////////////////////////////////////////
从派对的地点求一遍spfa可以得到回去路的最短距离,如果添加反边就是去的路的最短距离,淡然注意分开.....
#include<algorithm>
#include<queue>
#include<stdio.h>
#include<string.h>
#include<vector>
#include<math.h>
using namespace std; const int maxn = ;
const int oo = 0xfffffff; struct node
{
    int y, time;
    node(int y, int time):y(y), time(time){}
};
vector<node>gLeave[maxn];
vector<node>gBack[maxn];
int vLeave[maxn], vBack[maxn]; void spfa(vector<node> G[], int s, int v[])
{
    queue<int> Q;
    Q.push(s);     while(Q.size())
    {
        s = Q.front(), Q.pop();
        int len = G[s].size();         for(int i=; i<len; i++)
        {
            node q = G[s][i];             if(v[q.y] > v[s]+q.time)
            {
                v[q.y] = v[s]+q.time;
                Q.push(q.y);
            }
        }
    }
} int main()
{
    int N, M, S;     while(scanf("%d%d%d", &N, &M, &S) != EOF)
    {
        int i, a, b, t;         for(i=; i<=N; i++)
        {
            vLeave[i] = vBack[i] = oo;
            gLeave[i].clear();
            gBack[i].clear();
        }         vLeave[S] = vBack[S] = ;         for(i=; i<M; i++)
        {
            scanf("%d%d%d", &a, &b, &t);
            gLeave[b].push_back(node(a, t));
            gBack[a].push_back(node(b, t));
        }         spfa(gLeave, S, vLeave);
        spfa(gBack, S, vBack);         int ans = ;         for(i=; i<=N; i++)
            ans = max(ans, vLeave[i]+vBack[i]);         printf("%d\n", ans);
    }     return ;
}

D - Silver Cow Party的更多相关文章

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

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

  2. Silver Cow Party(最短路,好题)

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

  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 (Dijkstra)

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

  5. poj 3268 Silver Cow Party

                                                                                                       S ...

  6. POJ 3268 Silver Cow Party (最短路dijkstra)

    Silver Cow Party 题目链接: http://acm.hust.edu.cn/vjudge/contest/122685#problem/D Description One cow fr ...

  7. poj 3268 Silver Cow Party(最短路)

    Silver Cow Party Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 17017   Accepted: 7767 ...

  8. TOJ1693(Silver Cow Party)

    Silver Cow Party   Time Limit(Common/Java):2000MS/20000MS     Memory Limit:65536KByte Total Submit: ...

  9. POJ3268 Silver Cow Party(dijkstra+矩阵转置)

    Silver Cow Party Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 15156   Accepted: 6843 ...

  10. POJ 3268 Silver Cow Party (Dijkstra)

    Silver Cow Party Time Limit: 2000MS   Memory Limit: 65536K Total Submissions:28457   Accepted: 12928 ...

随机推荐

  1. c# 关于dispose

    只有针对非托管资源才需要调用dispose,包含托管资源包装了非托管资源这样的情况.也只有非托管资源调用dispose才会立即进行资源清理,托管资源即使调用dispose也还是交由gc自动完成,并非立 ...

  2. oracle中所有关于时间日期的问题总结

    select current_date as 当前会话时间,sysdate as 系统时间, systimestamp as 系统详细时间 from dual;

  3. SGU 152.Making round

    不断向下取直到,忽略的数累计到一个百分比,给当前百分比加1. 这道题要避免处理浮点数,用余数来处理,不然会wa 9 #include <iostream> #include <cma ...

  4. 系统默认字体Mac OS,Windows,XP,Lunix

    可查获的信息太少,目前得知的是以中文为例, OS : Helvetical,Lucida Grande(西文默认字体) Windows 7: Microsoft Yahei Xp : Simsun,T ...

  5. Oracle 面试宝典 - General Questions

    转自 http://www.orafaq.com/wiki/Interview_Questions Tell us about yourself/ your background. What are ...

  6. dedecms设置文章分页后,标题会带有序号的解决方法

    至于删除分页后标题后面的序号,找到include/arc.archives.class.php 打开,找到 if($i>1) $this->Fields['title'] = $this- ...

  7. XAMPP配置虚拟主机

    当你在本地进行单个网站建设和测试的时候,你只需要正常的安装一下XAMPP就好了.XAMPP本身是集成了apache.mysql和php的.然而当你本地测试站点一多的话,你就不得不考虑使用多个虚拟主机来 ...

  8. img超出div width时, jQuery动态改变图片显示大小

    参考: 1. http://blog.csdn.net/roman_yu/article/details/6641911 2. http://www.cnblogs.com/zyzlywq/archi ...

  9. Why is 0[0] syntactically valid in javascript?

    Why is 0[0] syntactically valid in javascript? 原文链接 偶然在一篇帖子中看到了这个问题,所以打算记录一下. var a = 0[0]; console. ...

  10. Python学习 - 使用BeautifulSoup来解析网页一:基础入门

    写技术博客主要就是总结和交流的,如果文章用错,请指正啊! 以前一直在使用SGMLParser,这个太费时间和精力了,现在为了毕业设计,改用BeautifulSoup来实现HTML页面的解析工作的. 一 ...