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 ...
随机推荐
- php中调用其他系统http接口的方法说明
使用函数: file_get_contents($url); 传入接口url及其参数:如 $url="http://192.168.1.1/test.jsp?id=1&type=2& ...
- tomcat发布项目时,空文件夹未发布成功
问题背景: 项目发布到服务器时,缺少文件夹,到时向此文件夹写数据时发生错误. 后来经查,缺少这个文件夹,项目部署发布时,并不会把空文件夹发布上去 解决: 1.在空文件中加入,一个文件.就可以发布成功 ...
- 极端气候频现 五款开发天气预报应用的API
http://www.csdn.net/article/2014-02-07/2818322-weather-forecast-api-for-developing-apps
- 获取Host文件权限 注册表导入
Windows Registry Editor Version 5.00 ;取得文件修改权限 [HKEY_CLASSES_ROOT\*\shell\runas] @="管理员权限" ...
- JQuery 实现鼠标经过图片高亮显示,其余图片变暗
效果图: 当鼠标经过图片时,其余图片变暗,来高亮显示当前图片,主要用的是对比度.当然你也可以先把其他图片默认变暗,鼠标经过时高亮显示,不过,无鼠标经过时整体图片都会是偏暗色调. 效果可以通过 三步实现 ...
- Sublime text3 JS语法检测工具安装及使用
Sublime text3 JS语法检测工具安装及使用 工具/原料 sublime text3 nodejs sublimeLinter sublimeLinter-jshint 方法/步骤 首先ct ...
- 最大乘积(Maximum Product,UVA 11059)
Problem D - Maximum Product Time Limit: 1 second Given a sequence of integers S = {S1, S2, ..., Sn}, ...
- 安卓AVD使用建议
问题描述:之前在安装了Android开发环境后,一开始并没有直接在Android手机和平板上进行调试,是使用的AVD模拟器工具.由于电脑的配置不是特别好,总感觉AVD的使用速度太慢,包括启动的时候还有 ...
- python json string和dict的转化
__author__ = 'SRC_TJ_XiaoqingZhang' import json data1 = {'b': 789, 'c': 456, 'a': 123} encode_json = ...
- C#中调用WIN32的API
最近在学习C#中的GDI部分,本来尝试编写一个字幕控件(其实还是用label比较合适),但是发现控件中用GDI将整个控件粉刷貌似不行(应该是我水平不行),所以就去捣鼓了下WIN32的DLL,发现用AP ...