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的更多相关文章

  1. CF - 96D - Volleyball

    题意:一个无向图,有n个点,m条边,每条边有距离w,每个点有两个属性(1.从这点出发能到的最远距离,2.从这点出发的费用(不论走多远都一样)),一个人要从点x到点y,问最小费用是多少. 题目链接:ht ...

  2. 【甘道夫】HBase(0.96以上版本号)过滤器Filter具体解释及实例代码

    说明: 本文參考官方Ref Guide,Developer API和众多博客.并结合实測代码编写.具体总结HBase的Filter功能,并附上每类Filter的对应代码实现. 本文尽量遵从Ref Gu ...

  3. HBase(0.96以上版本)过滤器Filter详解及实例代码

    说明: 本文参考官方Ref Guide,Developer API和众多博客,并结合实测代码编写,详细总结HBase的Filter功能,并附上每类Filter的相应代码实现. 本文尽量遵从Ref Gu ...

  4. spark1.0.2读取hbase(CDH0.96.1)上的数据

    基本环境: 我是在win7环境下,spark1.0.2,HBase0.9.6.1 使用工具:IDEA14.1, scala 2.11.6, sbt.我现在是测试环境使用的是单节点 1.使用IDEA创建 ...

  5. Flume-1.4.0和Hbase-0.96.0整合

    在使用Flume的时候,请确保你电脑里面已经搭建好Hadoop.Hbase.Zookeeper以及Flume.本文将以最新版的Hadoop-2.2.0.Hbase-0.96.0.Zookeeper-3 ...

  6. Entity Framework 6 Recipes 2nd Edition(9-6)译->管理断开时的并发

    9-6. 管理断开时的并发 问题 想要确保只接受在WCF客户端并发令牌未被修改的实体. 解决方案 我们有一个如Figure 9-6所示的模型. Figure 9-6订单实体模型 我们想通过WCF服务来 ...

  7. 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 ...

  8. 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 ...

  9. 【hbase0.96】基于hadoop搭建hbase的心得

    hbase是基于hadoop的hdfs框架做的分布式表格存储系统,所谓表格系统就是在k/v系统的基础上,对value部分支持column family和column,并支持多版本读写. hbase的工 ...

随机推荐

  1. c++ 一般虚函数

    类图: 代码: #include <iostream> using namespace std; class CFather //父类 { public: virtual void dis ...

  2. 揭秘:C++编译器的函数编译流程

    http://www.cnblogs.com/zhenjing/archive/2010/10/20/1856309.html C++中的类型查找过程相对简单,基本上就是名字查找,这里不再介绍. 对于 ...

  3. Linux环境搭建多项目SVN

    1.安装SVN #yum install subversion 2.创建版本库文件夹 #mkdir -p /var/svn/repos/pro1 (/var/svn/repos是根路径,pro1是项目 ...

  4. linq项目中例子实例

    在mvc项目中 var ls = (from i in gt.vendor_login                  join j in gt.vendor on i.vendor_id equa ...

  5. Python 学习笔记(十三)Python函数(一)

    函数基础 函数:函数是组织好的,可重复使用的,用来实现单一,或相关联功能的代码段. 函数能提高应用的模块性,和代码的重复利用率.Python提供了许多内建函数,比如print().可以自己创建函数,这 ...

  6. Navicat Premium 12 激活

    链接:https://pan.baidu.com/s/1R4WB2JjKd0UYnN00CpUPSA 提取码:e3wy (破解工具及软件安装包) 破解流程:https://www.jianshu.co ...

  7. to meet you

    1:Java特性 (1)平台无关性 一次编译到处运行 (2)GC 垃圾回收机制 (3)语言特性 泛型-反射机制-lambda表达式 (4)面向对象 面向对象语言-三大特性(封装,继承,多态) (5)类 ...

  8. async函数结合promise的小案例

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  9. canvas制作的烟花效果

    最近感觉canvas挺有意思的,在业余时间没事研究了一下,参考过网上一些思路,话不多说,开始啦. github地址:https://github.com/aWhiteBear/fireworks 演示 ...

  10. centos6 命令界面切换到图形界面

    要进入图形界面,首先要安装.所以应该先执行 yum groupinstall "X Window System" -y yum groupinstall "Desktop ...