D - Silver Cow Party
题目大意:
#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的更多相关文章
- 图论 ---- spfa + 链式向前星 ---- poj 3268 : Silver Cow Party
Silver Cow Party Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 12674 Accepted: 5651 ...
- Silver Cow Party(最短路,好题)
Silver Cow Party Time Limit:2000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Su ...
- POJ 3268 Silver Cow Party (双向dijkstra)
题目链接:http://poj.org/problem?id=3268 Silver Cow Party Time Limit: 2000MS Memory Limit: 65536K Total ...
- POJ 3268 Silver Cow Party (Dijkstra)
Silver Cow Party Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 13982 Accepted: 6307 ...
- poj 3268 Silver Cow Party
S ...
- POJ 3268 Silver Cow Party (最短路dijkstra)
Silver Cow Party 题目链接: http://acm.hust.edu.cn/vjudge/contest/122685#problem/D Description One cow fr ...
- poj 3268 Silver Cow Party(最短路)
Silver Cow Party Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 17017 Accepted: 7767 ...
- TOJ1693(Silver Cow Party)
Silver Cow Party Time Limit(Common/Java):2000MS/20000MS Memory Limit:65536KByte Total Submit: ...
- POJ3268 Silver Cow Party(dijkstra+矩阵转置)
Silver Cow Party Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 15156 Accepted: 6843 ...
- POJ 3268 Silver Cow Party (Dijkstra)
Silver Cow Party Time Limit: 2000MS Memory Limit: 65536K Total Submissions:28457 Accepted: 12928 ...
随机推荐
- switch语法之PHP
$a = 100; switch ($a) { case 100: echo '满分'; break; case $a >=60: echo '及格'; break; }
- 表中查询重复的数据,如何通过sql语句查询?
1.最直观的思路:要知道所有名字有重复人资料,首先必须知道哪个名字重复了:select name from emp group by name having count(*)>1所有名字重复人的 ...
- 对 const char* const &a 的理解
定义中用到&是独立引用. 比如: char i; char &a=i; 表示a是i的一个单独引用. 当有i='a'时,也有a='a'; 当有a='c'时,也有i='c'; 两个变量的标 ...
- yii2源码学习笔记(六)
Behvaior类,Behavior类是所有事件类的基类: 目录yii2\base\Behavior.php <?php /** * @link http://www.yiiframework. ...
- ecshop数据表
ecs_account_log:账户变动日志(注册用户充值.支付等记录信息) ecs_ad:广告表 ecs_admin_action:管理员权限表(定义了128项功能操作) ecs_admin_log ...
- 常见的mongodb可视化工具
一.MongoVue 1.MongoVUE是一款比较好用的MongoDB客户端工具,可以为大家提供一个高度.简洁可用的MongoDB管理界面. 2.通过MongoVUE,用户可以用树形.表格及bj ...
- Joomla插件汉化小程序
这两天在搞joomla插件,在看peter的视频,在此谢过他了.看到它汉化插件那个视频.反正闲着无聊,就写了一个Java小程序,方便使用joomla的人汉化插件.这个程序的方法很简单,你只要先运行ou ...
- mvc的真实含义
MVC是一个设计模式,它强制性的使应用程序的输入.处理和输出分开.使用 MVC应用程序被分成三个核心部件:模型(M).视图(V).控制器(C),它们各自处理自己的任务. 视图 : 视图是用户看到并与之 ...
- Swiper的简单实用方法
最近项目中有用到一个非常强大的组件idangerous.swiper.js的组件,这个组件能够实现幻灯片的播放效果,而且有各种3D效果,大家可以去试一下,效果很不错的说! 这是这个项目的api文档:h ...
- ubuntu install opengrok
总结: 1. 安装jdk和tomcat 2. 安装ctags 3. 解压opengrok.tar.gz包, 然后将source.war复制到tomcat/webapp下面 sudo cp -R ope ...