题意:

  就是求最小割点

解析:

  正向一遍spfa 反向一遍spfa  然后遍历每一条边,对于当前边 如果dis1[u] + dis2[v] + 1 <= k 那么就把这条边加入到网络流图中,

  每个点拆点 边权为1

  跑最大流即可

代码还是改的那一题。。。

  

  1. #include <iostream>
  2. #include <cstring>
  3. #include <cstdio>
  4. #include <queue>
  5. #include <cmath>
  6. #include <vector>
  7. #define mem(a,b) memset(a,b,sizeof(a))
  8. using namespace std;
  9. const int maxn = 1e3 + , INF = 0xfffffff, maxm = ;
  10. typedef long long LL;
  11. int n,m, cnt, s, t, k;
  12. int head[maxn], d[maxn], vis[maxn], dis1[maxn], dis2[maxn], head1[maxn], cur[maxn];
  13. int from[maxm], to[maxm];
  14. int bz[][], way[][];
  15.  
  16. struct edge
  17. {
  18. int u, v, c, next;
  19. }Edge[maxm << ];
  20.  
  21. void add_(int u, int v, int c)
  22. {
  23. Edge[cnt].u = u;
  24. Edge[cnt].v = v;
  25. Edge[cnt].c = c;
  26. Edge[cnt].next = head1[u];
  27. head1[u] = cnt++;
  28. }
  29.  
  30. void add_edge(int u, int v, int c)
  31. {
  32. add_(u, v, c);
  33. add_(v, u, );
  34. }
  35.  
  36. bool bfs()
  37. {
  38. mem(d, );
  39. queue<int> Q;
  40. Q.push(s);
  41. d[s] = ;
  42. while(!Q.empty())
  43. {
  44. int u = Q.front(); Q.pop();
  45. for(int i = head1[u]; i != -; i = Edge[i].next)
  46. {
  47. edge e = Edge[i];
  48. if(!d[e.v] && e.c > )
  49. {
  50. d[e.v] = d[u] + ;
  51. Q.push(e.v);
  52. if(e.v == t) return ;
  53. }
  54. }
  55. }
  56. return d[t] != ;
  57. }
  58.  
  59. int dfs(int u, int cap)
  60. {
  61. int ret = ;
  62. if(u == t || cap == )
  63. return cap;
  64. for(int &i = cur[u]; i != -; i = Edge[i].next)
  65. {
  66. edge e = Edge[i];
  67. if(d[e.v] == d[u] + && e.c > )
  68. {
  69. int V = dfs(e.v, min(e.c, cap));
  70. Edge[i].c -= V;
  71. Edge[i ^ ].c += V;
  72. ret += V;
  73. cap -= V;
  74. if(cap == ) break;
  75. }
  76. }
  77. if(cap > ) d[u] = -;
  78. return ret;
  79. }
  80.  
  81. int Dinic()
  82. {
  83. int ans = ;
  84. while(bfs())
  85. {
  86. memcpy(cur, head1, sizeof(head1));
  87. ans += dfs(s, INF);
  88. }
  89. return ans;
  90. }
  91.  
  92. struct node
  93. {
  94. int u, v, w, next;
  95. }Node[maxn * ];
  96.  
  97. void add(int u,int v,int w,int i)
  98. {
  99. Node[i].u = u;
  100. Node[i].v = v;
  101. Node[i].w = w;
  102. Node[i].next = head[u];
  103. head[u] = i;
  104. }
  105. void spfa(int s)
  106. {
  107. for(int i = ; i < maxn; i++) d[i] = INF;
  108. queue<int> Q;
  109. d[s] = ;
  110. mem(vis,);
  111. Q.push(s);
  112. vis[s] = ;
  113. while(!Q.empty())
  114. {
  115. int u = Q.front();Q.pop();
  116. vis[u] = ;
  117. for(int i=head[u]; i!=-; i=Node[i].next)
  118. {
  119. node e = Node[i];
  120. if(d[e.v] > d[u] + e.w)
  121. {
  122. d[e.v] = d[u] + e.w;
  123. if(!vis[e.v])
  124. {
  125. Q.push(e.v);
  126. vis[e.v] = ;
  127. }
  128. }
  129. }
  130.  
  131. }
  132. }
  133.  
  134. int main()
  135. {
  136. int T,A,B;
  137. while(~scanf("%d%d%d", &n, &m, &k))
  138. {
  139. if(n==&&m==&&k==)
  140. break;
  141. mem(way, );
  142. mem(bz, );
  143. mem(Node,);
  144. mem(head,-);
  145. mem(head1, -);
  146. cnt = ;
  147. for(int i=; i<m; i++)
  148. {
  149. scanf("%d%d",&from[i],&to[i]);
  150. if(!bz[from[i]][to[i]])
  151. {
  152. add(from[i],to[i],,i), bz[from[i]][to[i]] = ;
  153. way[from[i]][to[i]] = ;
  154. }
  155. }
  156. s = , t = n;
  157. spfa(s);
  158. mem(Node,);
  159. for(int i=; i<=n; i++)
  160. dis1[i] = d[i];
  161. mem(head,-);
  162. for(int i=; i<m; i++)
  163. add(to[i],from[i],,i);
  164. spfa(t);
  165. for(int i=; i<=n; i++)
  166. dis2[i] = d[i];
  167. mem(bz, );
  168. s = + n, t = n;
  169. for(int i = ; i <= n; i++)
  170. {
  171. for(int j = ; j <= n; j++)
  172. {
  173. if(way[i][j] && dis1[i] + dis2[j] + <= k)
  174. add_edge(i, j, INF);
  175. }
  176. add_edge(i, i + n, );
  177. }
  178.  
  179. printf("%d\n",Dinic());
  180. }
  181. return ;
  182. }

Destroying the bus stations HDU - 2485(最小割点)的更多相关文章

  1. 图论--网络流--最小割 HDU 2485 Destroying the bus stations(最短路+限流建图)

    Problem Description Gabiluso is one of the greatest spies in his country. Now he's trying to complet ...

  2. HDU 2485 Destroying the bus stations(!最大流∩!费用流∩搜索)

    Description Gabiluso is one of the greatest spies in his country. Now he’s trying to complete an “im ...

  3. HDUOJ----2485 Destroying the bus stations(2008北京现场赛A题)

    Destroying the bus stations                                                                          ...

  4. Destroying the bus stations

    Destroying the bus stations Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 1832   Acce ...

  5. hdu 2485 Destroying the bus stations 最小费用最大流

    题意: 最少需要几个点才能使得有向图中1->n的距离大于k. 分析: 删除某一点的以后,与它相连的所有边都不存在了,相当于点的容量为1.但是在网络流中我们只能直接限制边的容量.所以需要拆点来完成 ...

  6. HDU 2485 Destroying the bus stations (IDA*+ BFS)

    传送门:http://acm.hdu.edu.cn/showproblem.php?pid=2485 题意:给你n个点,m条相连的边,问你最少去掉几个点使从1到n最小路径>=k,其中不能去掉1, ...

  7. HDU 2485 Destroying the bus stations(费用流)

    http://acm.hdu.edu.cn/showproblem.php?pid=2485 题意: 现在要从起点1到终点n,途中有多个车站,每经过一个车站为1时间,现在要在k时间内到达终点,问至少要 ...

  8. HDU 2485 Destroying the bus stations

    2015 ACM / ICPC 北京站 热身赛 C题 #include<cstdio> #include<cstring> #include<cmath> #inc ...

  9. hdu 2485(最小费用最大流)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2485 思路:题目的意思是删除最少的点使1,n的最短路大于k.将点转化为边,容量为1,费用为0,然后就是 ...

随机推荐

  1. 九、xadmin菜单分组管理

    有的时候,我们的菜单很多很杂,想要把菜单进行分组以方便管理,如下 前一篇博文已经详细讲解了如何菜单自定义排序,自定义分组和排序其实写法类似: 要实现上面这个功能,分为以下几步: 1. 我们需要定义一个 ...

  2. VUE工程上线首页加载慢问题优化

    使用webpack-bundle-analyzer工具 下面介绍几种压缩文件的方式. 1.vue-router懒加载 2.工程文件打包的时候不生成.map文件 3.gzip压缩 4.CDN 5.VUE ...

  3. SDN 实验室学生们

    SDN实验室系列:https://edu.cnblogs.com/campus/fzu/SdnLab --研究生及本科生们的博客及GitHub链接.欢迎各位大佬招募. 研究生 2018级 姓名 博客地 ...

  4. 记一个JS树结构路径查找

    var a=[ { "id" : "0000", "text" : "R1", "children" ...

  5. 解决远程连接mysql很慢的方法(网络正常)

    最近用mysql命令行或者JDBC远程连接mysql速度很慢,而且远大于ping时间.上网搜了一下,解决方案如下: 在/etc/mysql/my.cnf文件的[mysqld]部分加入:skip-nam ...

  6. Python_内置函数之max

    源码: def max(*args, key=None): # known special case of max """ max(iterable, *[, defau ...

  7. Oracle 不小心删除undo数据文件以及磁盘空间不足导致不能登录的解决办法

    在一次测试中,由于导入的数据量过大导致事务一直提交失败因为磁盘空间不够用了,一检查发现是undo表空间不够用,于是重新创建了一个表空间,准备把之前的undo表空间删除,删除时却发现一直删不掉,因为它一 ...

  8. 【开讲啦】20181029 oracle教学笔记

    --创建表空间 create tablespace waterboss--表空间名称 datafile 'd:\waterboss.dbf'--用于设置物理文件名称 size 100m--用于设置表空 ...

  9. js的日期操作:String转date日期格式、求日期差

    一.在js中String类型转成date格式 var date = new Date("2018-9-21 14:58:43");//就是这么简单 二.date转String类型就 ...

  10. 解决小程序webview缓存机制

    在打开webview的时候在地址后面加上随机数或者字符串 并且H5页面使用文件hash