CF 96 D. Volleyball
D. Volleyball
http://codeforces.com/contest/96/problem/D
题意:
n个路口,m条双向路,每条长度为w。每个路口有一个出租车司机,最多可以乘坐这辆车走长度只要坐他的车,就必须交c元,最多可以载你走的长度为t的路。问从x到y的最小花费是多少。
分析:
第一遍SPFA求出每个点它能到的所有点,边权就是乘坐出租车的费用,第二遍直接跑最短路。稀疏图用了spfa
代码:
- #include<cstdio>
- #include<algorithm>
- #include<cstring>
- #include<cmath>
- #include<iostream>
- #include<cctype>
- #include<set>
- #include<vector>
- #include<queue>
- #include<map>
- #define fi(s) freopen(s,"r",stdin);
- #define fo(s) freopen(s,"w",stdout);
- using namespace std;
- typedef long long LL;
- inline int read() {
- int x=,f=;char ch=getchar();for(;!isdigit(ch);ch=getchar())if(ch=='-')f=-;
- for(;isdigit(ch);ch=getchar())x=x*+ch-'';return x*f;
- }
- const int N = ;
- struct ShortestPath{
- int head[N], len[N * N], nxt[N * N], to[N * N], q[N * N], En;
- LL dis[N], INF;
- bool vis[N];
- void add_edge(int u,int v,int w) {
- ++En; to[En] = v; len[En] = w; nxt[En] = head[u]; head[u] = En;
- }
- void spfa(int S) {
- memset(dis, 0x3f, sizeof(dis)); INF = dis[];
- int L = , R = ;
- dis[S] = ; q[++R] = S; vis[S] = true;
- while (L <= R) {
- int u = q[L ++]; vis[u] = false;
- for (int i = head[u]; i; i = nxt[i]) {
- int v = to[i];
- if (dis[v] > dis[u] + len[i]) {
- dis[v] = dis[u] + len[i];
- if (!vis[v]) q[++R] = v, vis[v] = true;
- }
- }
- }
- }
- }G1, G2;
- int main() {
- int n = read(), m = read(), S = read(), T = read();
- for (int i = ; i <= m; ++i) {
- int u = read(), v = read(), w = read();
- G1.add_edge(u, v, w); G1.add_edge(v, u, w);
- }
- for (int i = ; i <= n; ++i) {
- int d = read(), c = read();
- G1.spfa(i);
- for (int j = ; j <= n; ++j) {
- if (G1.dis[j] <= d && i != j) G2.add_edge(i, j, c); // 此处为单向边
- }
- }
- G2.spfa(S);
- if (G2.dis[T] == G2.INF) puts("-1");
- else cout << G2.dis[T];
- return ;
- }
CF 96 D. Volleyball的更多相关文章
- CF - 96D - Volleyball
题意:一个无向图,有n个点,m条边,每条边有距离w,每个点有两个属性(1.从这点出发能到的最远距离,2.从这点出发的费用(不论走多远都一样)),一个人要从点x到点y,问最小费用是多少. 题目链接:ht ...
- 【甘道夫】HBase(0.96以上版本号)过滤器Filter具体解释及实例代码
说明: 本文參考官方Ref Guide,Developer API和众多博客.并结合实測代码编写.具体总结HBase的Filter功能,并附上每类Filter的对应代码实现. 本文尽量遵从Ref Gu ...
- HBase(0.96以上版本)过滤器Filter详解及实例代码
说明: 本文参考官方Ref Guide,Developer API和众多博客,并结合实测代码编写,详细总结HBase的Filter功能,并附上每类Filter的相应代码实现. 本文尽量遵从Ref Gu ...
- spark1.0.2读取hbase(CDH0.96.1)上的数据
基本环境: 我是在win7环境下,spark1.0.2,HBase0.9.6.1 使用工具:IDEA14.1, scala 2.11.6, sbt.我现在是测试环境使用的是单节点 1.使用IDEA创建 ...
- Flume-1.4.0和Hbase-0.96.0整合
在使用Flume的时候,请确保你电脑里面已经搭建好Hadoop.Hbase.Zookeeper以及Flume.本文将以最新版的Hadoop-2.2.0.Hbase-0.96.0.Zookeeper-3 ...
- Entity Framework 6 Recipes 2nd Edition(9-6)译->管理断开时的并发
9-6. 管理断开时的并发 问题 想要确保只接受在WCF客户端并发令牌未被修改的实体. 解决方案 我们有一个如Figure 9-6所示的模型. Figure 9-6订单实体模型 我们想通过WCF服务来 ...
- ORA-00494: enqueue [CF] held for too long (more than 900 seconds) by 'inst 1, osid 5166'
凌晨收到同事电话,反馈应用程序访问Oracle数据库时报错,当时现场现象确认: 1. 应用程序访问不了数据库,使用SQL Developer测试发现访问不了数据库.报ORA-12570 TNS:pac ...
- Codeforces CF#628 Education 8 D. Magic Numbers
D. Magic Numbers time limit per test 2 seconds memory limit per test 256 megabytes input standard in ...
- 【hbase0.96】基于hadoop搭建hbase的心得
hbase是基于hadoop的hdfs框架做的分布式表格存储系统,所谓表格系统就是在k/v系统的基础上,对value部分支持column family和column,并支持多版本读写. hbase的工 ...
随机推荐
- (六)Linux下的压缩命令
======================================================================================== .zip格式的压缩和解 ...
- 6、Web Service-拦截器
1.为什么CXF设置拦截器 为了在webservice请求过程中,能动态操作请求和响应数据, CXF设计了拦截器.拦截器分类 1.按所处的位置分:服务器端拦截器,客户端拦截器 2.按消息的方向分:入拦 ...
- [Python 多线程] Semaphore、BounedeSemaphore (十二)
Semaphore 信号量,信号量对象内部维护一个倒计数器,每一次acquire都会减1,当acquire方法发现计数为0就阻塞请求的线程,直到其它线程对信号量release后,计数大于0,恢复阻塞的 ...
- WEB安全 魔术引号及注入类型
一.魔术引号 1. magic_quotes_gpc 变量 什么是魔术引号 Warning本特性已自 PHP 5.3.0 起废弃并将自 PHP 5.4.0 起移除.当打开时,所有的 '(单引号),&q ...
- HDU 1829 A Bug's Life (种类并查集)
传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1829 A Bug's Life Time Limit: 15000/5000 MS (Java/Oth ...
- CentOS查看卸载openjdk
1.查看openjdk版本 java -versionjava version "1.7.0_51" OpenJDK Runtime Environment (rhel-2.4.5 ...
- 客户端对象模型之列表数据导出到Excel
1,废话不多话,直接上代码,留着以后做类似功能时Copy一下!有需要的朋友也可以参考一下. <!DOCTYPE html> <html xmlns="http://www. ...
- JS模拟Dictionary
function Map() { this.keys = new Array(); this.data = new Array(); //添加键值对 this.set = function (key, ...
- Git IDEA Move or commit them before merge
提交代码遇到这个问题. Move or commit them before merge 百度了一下都是在Gitbash 中敲命令. 在团队协作中 你总不能去敲命令吧 后来在组长的怂恿下,我删除了一个 ...
- C++编译器是如何管理类和对象的,类的成员函数和成员变量
C++中的class从面向对象理论出发,将变量(属性)和函数(方法)集中定义在一起,用于描述现实世界中的类.从计算机的角度,程序依然由数据段(栈区内存)和代码段(代码区内存)构成. #include ...