题意:

有n头牛去第x个点开party(有点高大上~),单向路,去到还得回来,问这n头牛每一头花费的总时间的最大值是多少

模板spfa:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <queue>
#define mem(a,b) memset(a,b,sizeof(a))
using namespace std;
const int maxn = , INF = 0xfffffff;
int n, m, x;
int head[maxn], vis[maxn], d[maxn], dis[maxn];
struct node{
int u,v,d,next;
}Node[maxn]; void add(int u, int v, int d, int i)
{
Node[i].u = u;
Node[i].v = v;
Node[i].d = d;
Node[i].next = head[u];
head[u] = i;
} void spfa(int s)
{
mem(vis,);
queue<int> Q;
for(int i=; i<=n; ++i) d[i] = INF;
d[s] = ;
Q.push(s);
vis[s] = ;
while(!Q.empty())
{
int u = Q.front(); Q.pop();
vis[u] = ;
for(int i=head[u]; i!=-; i=Node[i].next)
{
node e = Node[i];
if(d[e.v] > d[u] + e.d)
{
d[e.v] = d[u] + e.d;
if(!vis[e.v])
{
Q.push(e.v);
vis[e.v] = ;
}
}
}
}
} int main()
{
while(~scanf("%d%d%d",&n,&m,&x))
{
mem(Node,);
mem(head,-);
mem(dis,);
for(int i=; i<m; i++)
{
int u,v,d;
scanf("%d%d%d",&u,&v,&d);
add(u,v,d,i);
}
int maxx = -INF;
spfa(x);
for(int i=;i<=n;i++)
dis[i] = d[i];
for(int i=;i<=n;i++)
{
spfa(i);
int temp1 = d[x];
int temp2 = dis[i];
maxx = max(maxx,temp1+temp2);
}
printf("%d\n",maxx); } return ;
}

POJ3268(Silver Cow Party)的更多相关文章

  1. TOJ1693(Silver Cow Party)

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

  2. 【POJ3268】Silver Cow Party 最短

    意甲冠军:一群奶牛去的地方.去回,然后回去寻找最伟大值. 题解:两遍最短路,结束.邻接矩阵存边能够避免建反图. #include <cstdio> #include <cstring ...

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

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

  4. 【POJ - 3268 】Silver Cow Party (最短路 Dijkstra算法)

    Silver Cow Party Descriptions 给出n个点和m条边,接着是m条边,代表从牛a到牛b需要花费c时间,现在所有牛要到牛x那里去参加聚会,并且所有牛参加聚会后还要回来,给你牛x, ...

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

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

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

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

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

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

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

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

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

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

随机推荐

  1. Excel 2007 底层实现方式

    一.EXCEL的底层实现 能力有限,了解的比较浅,有不足之处望指正,首先看下图: 一. excel2007是使用xml格式来存储的,把一个excel文件后缀改为.zip,打开之后就直接可以看到一个ex ...

  2. (转)Ubuntu init启动流程分析

    原文 upstart homepage 现行的Linux distros主流的有两种init方式:一种是广为流传的System V initialization,它来源于Unix并且至今仍被各种Lin ...

  3. 马加爵遗书 VS 药家鑫遗书

          前言:今天是贰零壹柒年最后一个工作日,亦是2017年12月29日,因为明天就放元旦假了,公司同事比往常相对轻松些.中午吃完午饭,在办公室大家有说有笑,有人说姓马的人都挺牛X啊,比如:马云, ...

  4. [Spark][Python]Mapping Single Rows to Multiple Pairs

    Mapping Single Rows to Multiple Pairs目的: 把如下的这种数据, Input Data 00001 sku010:sku933:sku02200002 sku912 ...

  5. vue 过滤器基本使用

    Vue.js 允许你自定义过滤器,可被用于一些常见的文本格式化,例如时间戳格式化. 过滤器可以用在: 双花括号插值 v-bind 表达式 (2.1.0+ 开始支持). 过滤器应该被添加在 JavaSc ...

  6. Centos7.4安装kvm虚拟机(使用virt-manager管理)

    之前介绍了使用WebVirtMgr或Openstack来部署及管理kvm虚拟机,下面简单介绍centos7.4下使用virt-manager部署及管理kvm虚拟机的做法: 0)KVM是什么 KVM(K ...

  7. kvm虚拟化管理平台WebVirtMgr部署-完整记录(2)

    继上一篇kvm虚拟化管理平台WebVirtMgr部署-完整记录(1),接下来说说WebVirtMgr的日常配置:添加宿主机,创建虚机,磁盘扩容,快照等具体操作记录如下: 一.配置宿主机1.登录WebV ...

  8. SQL基础语句总结

    前言: SQL 是用于访问和处理数据库的标准的计算机语言. 什么是 SQL? SQL 指结构化查询语言SQL 使我们有能力访问数据库SQL 是一种 ANSI 的标准计算机语言编者注:ANSI,美国国家 ...

  9. swift 各种学习

    swift使用cocoapods引用oc第三方库 1. 创建桥接文件 2. 在主工程的 build Settings 搜索 bridge   设置 Objective-C Bridging Headi ...

  10. SCRUM 12.18

    明天就是编译课设的第二次中期考核了,大家都感到有一些压力. 所以我们决定今天减少一些工作量. 工作任务分配依旧如往常 成员 任务 彭林江 落实API 郝倩 研究遍历美团数据方法 牛强 落实意见反馈功能 ...