D. Volleyball

http://codeforces.com/contest/96/problem/D

题意:

  n个路口,m条双向路,每条长度为w。每个路口有一个出租车司机,最多可以乘坐这辆车走长度只要坐他的车,就必须交c元,最多可以载你走的长度为t的路。问从x到y的最小花费是多少。

分析:

  第一遍SPFA求出每个点它能到的所有点,边权就是乘坐出租车的费用,第二遍直接跑最短路。稀疏图用了spfa

代码:

  1. #include<cstdio>
  2. #include<algorithm>
  3. #include<cstring>
  4. #include<cmath>
  5. #include<iostream>
  6. #include<cctype>
  7. #include<set>
  8. #include<vector>
  9. #include<queue>
  10. #include<map>
  11. #define fi(s) freopen(s,"r",stdin);
  12. #define fo(s) freopen(s,"w",stdout);
  13. using namespace std;
  14. typedef long long LL;
  15.  
  16. inline int read() {
  17. int x=,f=;char ch=getchar();for(;!isdigit(ch);ch=getchar())if(ch=='-')f=-;
  18. for(;isdigit(ch);ch=getchar())x=x*+ch-'';return x*f;
  19. }
  20.  
  21. const int N = ;
  22.  
  23. struct ShortestPath{
  24. int head[N], len[N * N], nxt[N * N], to[N * N], q[N * N], En;
  25. LL dis[N], INF;
  26. bool vis[N];
  27. void add_edge(int u,int v,int w) {
  28. ++En; to[En] = v; len[En] = w; nxt[En] = head[u]; head[u] = En;
  29. }
  30. void spfa(int S) {
  31. memset(dis, 0x3f, sizeof(dis)); INF = dis[];
  32. int L = , R = ;
  33. dis[S] = ; q[++R] = S; vis[S] = true;
  34. while (L <= R) {
  35. int u = q[L ++]; vis[u] = false;
  36. for (int i = head[u]; i; i = nxt[i]) {
  37. int v = to[i];
  38. if (dis[v] > dis[u] + len[i]) {
  39. dis[v] = dis[u] + len[i];
  40. if (!vis[v]) q[++R] = v, vis[v] = true;
  41. }
  42. }
  43. }
  44. }
  45. }G1, G2;
  46.  
  47. int main() {
  48. int n = read(), m = read(), S = read(), T = read();
  49. for (int i = ; i <= m; ++i) {
  50. int u = read(), v = read(), w = read();
  51. G1.add_edge(u, v, w); G1.add_edge(v, u, w);
  52. }
  53. for (int i = ; i <= n; ++i) {
  54. int d = read(), c = read();
  55. G1.spfa(i);
  56. for (int j = ; j <= n; ++j) {
  57. if (G1.dis[j] <= d && i != j) G2.add_edge(i, j, c); // 此处为单向边
  58. }
  59. }
  60. G2.spfa(S);
  61. if (G2.dis[T] == G2.INF) puts("-1");
  62. else cout << G2.dis[T];
  63. return ;
  64. }

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. (六)Linux下的压缩命令

    ======================================================================================== .zip格式的压缩和解 ...

  2. 6、Web Service-拦截器

    1.为什么CXF设置拦截器 为了在webservice请求过程中,能动态操作请求和响应数据, CXF设计了拦截器.拦截器分类 1.按所处的位置分:服务器端拦截器,客户端拦截器 2.按消息的方向分:入拦 ...

  3. [Python 多线程] Semaphore、BounedeSemaphore (十二)

    Semaphore 信号量,信号量对象内部维护一个倒计数器,每一次acquire都会减1,当acquire方法发现计数为0就阻塞请求的线程,直到其它线程对信号量release后,计数大于0,恢复阻塞的 ...

  4. WEB安全 魔术引号及注入类型

    一.魔术引号 1. magic_quotes_gpc 变量 什么是魔术引号 Warning本特性已自 PHP 5.3.0 起废弃并将自 PHP 5.4.0 起移除.当打开时,所有的 '(单引号),&q ...

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

  6. CentOS查看卸载openjdk

    1.查看openjdk版本 java -versionjava version "1.7.0_51" OpenJDK Runtime Environment (rhel-2.4.5 ...

  7. 客户端对象模型之列表数据导出到Excel

    1,废话不多话,直接上代码,留着以后做类似功能时Copy一下!有需要的朋友也可以参考一下. <!DOCTYPE html> <html xmlns="http://www. ...

  8. JS模拟Dictionary

    function Map() { this.keys = new Array(); this.data = new Array(); //添加键值对 this.set = function (key, ...

  9. Git IDEA Move or commit them before merge

    提交代码遇到这个问题. Move or commit them before merge 百度了一下都是在Gitbash 中敲命令. 在团队协作中 你总不能去敲命令吧 后来在组长的怂恿下,我删除了一个 ...

  10. C++编译器是如何管理类和对象的,类的成员函数和成员变量

    C++中的class从面向对象理论出发,将变量(属性)和函数(方法)集中定义在一起,用于描述现实世界中的类.从计算机的角度,程序依然由数据段(栈区内存)和代码段(代码区内存)构成. #include ...