n<=50000,m<=50000的图,给s和t,问有多少点对$(a,b)$满足

嗯。

不会。

首先最短路DAG造出来,然后两个条件转述一下:条件一,$N_a$表示从s到t经过a的路径,$N_a+N_b=N_t$;条件二,在最短路DAG上A不能到B,B不能到A。

条件一就迪杰斯特拉的时候算一下N,注意不在最短路DAG上的点$N_i=0$;然后对每个$N_t-N_b$的值存一个bitset,用以表示值为这么多的点的状态,枚举a查多少$N_t-N_b=N_a$即可。

条件二就正反拓扑序跑一下,然后传递闭包算出来即可知道最短路图上哪些点能到a和a能到哪些点,把这些点设为不可达点,取个交集即可算出每个a能和哪些b在条件二下配对。

然后就没了。

  1. #include<stdio.h>
  2. #include<string.h>
  3. #include<algorithm>
  4. #include<stdlib.h>
  5. #include<bitset>
  6. #include<queue>
  7. #include<math.h>
  8. //#include<time.h>
  9. //#include<iostream>
  10. using namespace std;
  11.  
  12. int n,m,s,t;
  13. #define maxn 50011
  14. #define maxm 100011
  15. #define LL long long
  16.  
  17. struct Edge{int to,next,v;};
  18. struct qnode
  19. {
  20. int id; LL v;
  21. bool operator < (const qnode &b) const {return v<b.v;}
  22. bool operator > (const qnode &b) const {return v>b.v;}
  23. };
  24. struct Graph
  25. {
  26. Edge edge[maxm<<]; int first[maxn],le;
  27. Graph() {memset(first,,sizeof(first)); le=;}
  28. void in(int x,int y,int v) {Edge &e=edge[le]; e.to=y; e.v=v; e.next=first[x]; first[x]=le++;}
  29. void insert(int x,int y,int v) {in(x,y,v); in(y,x,v);}
  30. priority_queue<qnode,vector<qnode>,greater<qnode> > q;
  31. void dijkstra(int s,LL *dis,LL *f)
  32. {
  33. for (int i=;i<=n;i++) dis[i]=1e18,f[i]=;
  34. dis[s]=; f[s]=;
  35. q.push((qnode){s,});
  36. while (!q.empty())
  37. {
  38. const int now=q.top().id; const LL d=q.top().v; q.pop();
  39. if (d!=dis[now]) continue;
  40. for (int i=first[now];i;i=edge[i].next)
  41. {
  42. const Edge &e=edge[i];
  43. if (dis[e.to]>dis[now]+e.v)
  44. {
  45. dis[e.to]=dis[now]+e.v;
  46. f[e.to]=f[now];
  47. q.push((qnode){e.to,dis[e.to]});
  48. }
  49. else if (dis[e.to]==dis[now]+e.v) f[e.to]+=f[now];
  50. }
  51. }
  52. }
  53. }g;
  54.  
  55. LL dis[][maxn],f[][maxn],val[maxn];
  56. bitset<maxn> where[maxn],can[][maxn];
  57. int indo[maxn],head,tail,que[maxn];
  58. bool check(int x,int y,int v,int ty) {return dis[ty][x]+v+dis[ty^][y]==dis[][t];}
  59. void toposort(int ty)
  60. {
  61. memset(indo,,sizeof(indo));
  62. for (int i=;i<=n;i++)
  63. for (int j=g.first[i];j;j=g.edge[j].next)
  64. {
  65. const Edge &e=g.edge[j];
  66. if (check(i,e.to,e.v,ty)) indo[e.to]++;
  67. }
  68. head=tail=;
  69. for (int i=;i<=n;i++) if (indo[i]==) que[tail++]=i;
  70. while (head!=tail)
  71. {
  72. const int now=que[head++];
  73. for (int i=g.first[now];i;i=g.edge[i].next)
  74. {
  75. const Edge &e=g.edge[i];
  76. if (!check(now,e.to,e.v,ty)) continue;
  77. indo[e.to]--; if (indo[e.to]==) que[tail++]=e.to;
  78. can[ty][e.to]&=can[ty][now];
  79. }
  80. }
  81. }
  82.  
  83. qnode list[maxn];
  84. int main()
  85. {
  86. scanf("%d%d%d%d",&n,&m,&s,&t);
  87. for (int i=,x,y,v;i<=m;i++)
  88. {
  89. scanf("%d%d%d",&x,&y,&v);
  90. g.insert(x,y,v);
  91. }
  92. g.dijkstra(s,dis[],f[]); g.dijkstra(t,dis[],f[]);
  93.  
  94. if (dis[][t]==1e18) {printf("%lld\n",1ll*n*(n-)/); return ;}
  95.  
  96. for (int i=;i<=n;i++) can[][i].set(),can[][i].set(),can[][i][i]=can[][i][i]=;
  97. toposort(); toposort();
  98.  
  99. for (int i=;i<=n;i++) if (dis[][i]+dis[][i]!=dis[][t]) val[i]=; else val[i]=f[][i]*f[][i];
  100. for (int i=;i<=n;i++) list[i]=((qnode){i,val[i]});
  101. sort(list+,list++n);
  102. list[n+].v=1e18;
  103. for (int i=,j=;i<=n+;i++) if (list[i].v!=list[i-].v)
  104. {
  105. int now=j;
  106. for (;j<i;j++) where[now][list[j].id]=;
  107. }
  108.  
  109. LL ans=;
  110. for (int i=;i<=n;i++)
  111. {
  112. int L=,R=n+; LL tmp=f[][t]-val[i];
  113. while (L<R)
  114. {
  115. int mid=(L+R)>>;
  116. if (list[mid].v>=tmp) R=mid;
  117. else L=mid+;
  118. }
  119. if (L!=n+) ans+=(where[L]&can[][i]&can[][i]).count();
  120. }
  121. printf("%lld\n",ans/);
  122. return ;
  123. }

「CodePlus 2017 11 月赛」大吉大利,晚上吃鸡!的更多相关文章

  1. 「CodePlus 2017 11 月赛」大吉大利,晚上吃鸡!(dij+bitset)

    从S出发跑dij,从T出发跑dij,顺便最短路计数. 令$F(x)$为$S$到$T$最短路经过$x$的方案数,显然这个是可以用$S$到$x$的方案数乘$T$到$x$的方案数来得到. 然后第一个条件就变 ...

  2. LOJ6252. 「CodePlus 2017 11 月赛」大吉大利,晚上吃鸡! 最短路+bitset

    题目传送门 https://loj.ac/problem/6252 https://lydsy.com/JudgeOnline/problem.php?id=5109 题解 首先跑最短路,只保留 \( ...

  3. loj #6250. 「CodePlus 2017 11 月赛」找爸爸

    #6250. 「CodePlus 2017 11 月赛」找爸爸 题目描述 小 A 最近一直在找自己的爸爸,用什么办法呢,就是 DNA 比对. 小 A 有一套自己的 DNA 序列比较方法,其最终目标是最 ...

  4. [LOJ 6249]「CodePlus 2017 11 月赛」汀博尔

    Description 有 n 棵树,初始时每棵树的高度为 H_i,第 i 棵树每月都会长高 A_i.现在有个木料长度总量为 S 的订单,客户要求每块木料的长度不能小于 L,而且木料必须是整棵树(即不 ...

  5. [LOJ 6248]「CodePlus 2017 11 月赛」晨跑

    Description “无体育,不清华”.“每天锻炼一小时,健康工作五十年,幸福生活一辈子” 在清华,体育运动绝对是同学们生活中不可或缺的一部分.为了响应学校的号召,模范好学生王队长决定坚持晨跑.不 ...

  6. 「CodePlus 2017 11 月赛」Yazid 的新生舞会(树状数组/线段树)

    学习了新姿势..(一直看不懂大爷的代码卡了好久T T 首先数字范围那么小可以考虑枚举众数来计算答案,设当前枚举到$x$,$s_i$为前$i$个数中$x$的出现次数,则满足$2*s_r-r > 2 ...

  7. 「CodePlus 2017 11 月赛」可做题

    这种题先二进制拆位,显然改的位置只有每一段确定的数的开头和结尾,只需要对于每一个可决策位置都尝试一下填1和0,然后取min即可. #include<iostream> #include&l ...

  8. 「CodePlus 2017 11 月赛」Yazid 的新生舞会

    n<=500000的数字,问有多少个区间的众数出现次数严格大于区间长度的一半. 这么说来一个区间就一个众数了,所以第一反应是枚举数字,对下标进行处理.然后没有第二反应.很好. 在枚举一个数字的时 ...

  9. [LOJ#6259]「CodePlus 2017 12 月赛」白金元首与独舞

    [LOJ#6259]「CodePlus 2017 12 月赛」白金元首与独舞 试题描述 到河北省 见斯大林 / 在月光下 你的背影 / 让我们一起跳舞吧 うそだよ~ 河北省怎么可能有 Stalin. ...

随机推荐

  1. APP统计

    APP统计就是统计用户使用app的各项指标,比如说日活跃量,页面打开次数,新增用户数量,用户年龄分布,用户地区分布,用户性别分布以及用户使用时间段等等.将统计出来的用户信息进行比对分析,可以服务公司的 ...

  2. snort + barnyard2如何正确读取snort.unified2格式的数据集并且入库MySQL(图文详解)

    不多说,直接上干货! 为什么,要写这篇论文? 是因为,目前科研的我,正值研三,致力于网络安全.大数据.机器学习研究领域! 论文方向的需要,同时不局限于真实物理环境机器实验室的攻防环境.也不局限于真实物 ...

  3. jstat命令-帮助优化java性能

    jstat命令使用 jstat命令可以查看堆内存各部分的使用量,以及加载类的数量.命令的格式如下: jstat [-命令选项] [vmid] [间隔时间/毫秒] [查询次数]

  4. 使用 ArrayAdapter 来定制 ListView

    一个 ListView,其宽高都设为 match_parent,可以更省资源. activity_main.xml <ListView android:id="@+id/list_Vi ...

  5. JavaScript——class与原型对象

    原型对象的意义 通过new 一个构造函数,我们能够获得一个实例,在new 的过程中,程序会在内存中申请一块区域,同时我们可以加参数,所以每个对象都不一样. 原型对象则是同一个构造函数 new 出来的所 ...

  6. Android源码之陌陌源码

    本源码是一个老版本的陌陌源码,翻了翻代码,发现有完整的登陆注册功能(基于本地)其余都是静态页面.有需要的朋友可以拿去研究一下.其中登陆账号是86930007密码为123456.   这个项目源码我也上 ...

  7. js 类似于移动端购物车删除,左移动删除

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

  8. jQuery 全选、全不选、反选

    <!DOCTYPE html> <html lang="en"> <head> <title></title> < ...

  9. cpio - 存取归档包中的文件

    总览 (SYNOPSIS) cpio {-o|--create} [-0acvABLV] [-C bytes] [-H format] [-M message] [-O [[user@]host:]a ...

  10. Go语言 之md5加密

    //方式一 func getMd5String1(str string) string { m := md5.New() _, err := io.WriteString(m, str) if err ...