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 ...
随机推荐
- 微软企业库Microsoft Enterprise Library的相关文章链接
微软企业库4.1学习笔记 http://blog.csdn.net/anyqu/article/category/1228691/3 黄聪:Enterprise Library 5.0 系列教程 ww ...
- Nginx配置http强制跳转到https
目的:访问http://sdk.open.test.com/时强制自动跳转到https://sdk.open.test.com/ 修改nginx站点配置文件sdk.open.test.com.conf ...
- 分享整理的sql脚本
1. 表空间使用率 SQL> select a.tablespace_name, 2 round(a.total_size) "total_size M" ...
- javascript基础学习(六)
javascript之对象 学习要点: 对象的属性和方法 对象的原型 一.对象 对象其实就是一种引用类型,而对象的值就是引用对象的实例. 二.创建对象 在javascript中有两种对象,一种是系统内 ...
- JDBC标准事物编程模式
事物简介: 事物是一种数据库中保证交易可靠的机制,JDBC支持数据库中事物的概念,默认情况下事物是默认提交的. 事物的特性: 1.事物必须是原子工作单元,对于其数据的修改,要么都执行,要么都不执行2. ...
- slf4j与log4j
推荐使用SLF4J(Simple Logging Facade for Java)作为日志的api,SLF4J是一个用于日志系统的简单Facade,允许最终用户在部署其应用时使用其所希望的日志系统. ...
- 微软SQLHelper.cs类
using System; using System.Data; using System.Xml; using System.Data.SqlClient; using System.Collect ...
- php文件加锁 lock_sh ,lock_ex
文件锁有两种:共享锁和排他锁,也就是读锁(LOCK_SH)和写锁(LOCK_EX) 文件的锁一般这么使用: $fp = fopen("filename", "a" ...
- jQuery运维开发之第十七天
JQuery 学习参考网址http://jquery.cuishifeng.cn/ python中叫模块,在DOM/BOM/Javascript中叫类库 现在的JQ版本有:1.x 2.x 3.x 建议 ...
- HTML用法小摘录
一.网页地址栏上小图标标签添加写法: <link rel="Shortcut Icon" href="~/Content/ico/glasses.ico" ...