Destroying the bus stations
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 1832   Accepted: 595

Description

Gabiluso is one of the greatest spies in his country. Now he's trying to complete an “impossible” mission - to make it slow for the army of City Colugu to reach the airport. City Colugu has n bus stations and m roads. Each road connects two bus stations directly, and all roads are one way streets. In order to keep the air clean, the government bans all military vehicles. So the army must take buses to go to the airport. There may be more than one road between two bus stations. If a bus station is destroyed, all roads connecting that station will become no use. What's Gabiluso needs to do is destroying some bus stations to make the army can't get to the airport in k minutes. It takes exactly one minute for a bus to pass any road. All bus stations are numbered from 1 to n. The No.1 bus station is in the barrack and the No. n station is in the airport. The army always set out from the No. 1 station.

No.1 station and No. n station can't be destroyed because of the heavy guard. Of course there is no road from No.1 station to No. n station.

Please help Gabiluso to calculate the minimum number of bus stations he must destroy to complete his mission.

Input

There are several test cases. Input ends with three zeros. 
For each test case: 
The first line contains 3 integers, n, m and k. (0 < n <= 50,0 < m <= 4000, 0 < k < 1000) 
Then m lines follows. Each line contains 2 integers, s and f, indicating that there is a road from station No. s to station No. f.

Output

For each test case, output the minimum number of stations Gabiluso must destroy.

Sample Input

  1. 5 7 3
  2. 1 3
  3. 3 4
  4. 4 5
  5. 1 2
  6. 2 5
  7. 1 4
  8. 4 5
  9. 0 0 0

Sample Output

  1. 2

大神的标程

  1. #include <iostream>
  2. #include <cstring>
  3.  
  4. using namespace std;
  5. const int maxm=;
  6. const int maxn=;
  7.  
  8. struct aaa
  9. {
  10. int s,f,next;
  11. };
  12. aaa c[maxm];
  13. int sta[maxn],fa[maxn],zh[maxn];
  14. int d[maxn][maxn],e[maxn];
  15. bool b[maxn];
  16. int n,m,now,tot;
  17. bool goal;
  18. void ins(int s,int f)
  19. {
  20. now++;
  21. c[now].s=s,c[now].f=f;c[now].next=sta[s],sta[s]=now;
  22. }
  23.  
  24. void bfs()
  25. {
  26. int i,c1,op,k,t;
  27. c1=,op=;
  28. for(i=;i<=n;i++)
  29. fa[i]=;
  30. zh[]=;
  31. fa[]=-;
  32. while(c1<op)
  33. {
  34. c1++,k=zh[c1];
  35. for(t=sta[k];t;t=c[t].next)
  36. if(b[c[t].f]&&fa[c[t].f]==)
  37. {
  38. zh[++op]=c[t].f;
  39. fa[c[t].f]=c[t].s;
  40. if(c[t].f==n) break;
  41. }
  42. if(fa[n]) break;
  43. }
  44. }
  45.  
  46. void dfs(int deep)
  47. {
  48. int i,c1,op,l,k;
  49. if(goal) return;
  50. bfs();
  51. if(fa[n]==)
  52. {
  53. goal=true;return;
  54. }
  55. l=;
  56. for(k=n;k>;k=fa[k])
  57. l++,d[deep][l]=k;
  58. if(l>m)
  59. { goal=true;
  60. return;
  61. }
  62. if(deep>tot) return;
  63. for(i=;i<=l;i++)
  64. {
  65. b[d[deep][i]]=false;
  66. if(e[d[deep][i]]==) dfs(deep+);
  67. b[d[deep][i]]=true;
  68. e[d[deep][i]]++;
  69. }
  70. for(i=;i<=l;i++)
  71. e[d[deep][i]]--;
  72. }
  73.  
  74. int make()
  75. {
  76. int i,j;
  77. goal=false;
  78. for(i=;i<=n;i++)
  79. {
  80. tot=i;
  81. for(j=;j<=n;j++)
  82. b[j]=true;
  83. memset(e,,sizeof(e));
  84. dfs();
  85. if(goal) return i;
  86. }
  87. return n;
  88. }
  89.  
  90. int main()
  91. {
  92. int i,s,f,g;
  93. while(true)
  94. {
  95. cin>>n>>g>>m;
  96. if(n==) break;
  97. memset(sta,,sizeof(sta));
  98. now=;
  99. for(i=;i<=g;i++)
  100. {
  101. cin>>s>>f;
  102. ins(s,f);
  103. }
  104. cout<<make()<<endl;
  105. }
  106. return ;
  107. }

Destroying the bus stations的更多相关文章

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

    Destroying the bus stations                                                                          ...

  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. 图论--网络流--最小割 HDU 2485 Destroying the bus stations(最短路+限流建图)

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

  4. POJ 3921 Destroying the bus stations 沿着最短路迭代加深搜索

    题目:给出一个图,问最少删除多少个点,使得从点1到点n经过的点数超过k个. 分析: 上网搜了一下,发现很多人用网络流做的,发现我不会.再后来看到这篇说网络流的做法是错的,囧. 后来发现点数有点少,直接 ...

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

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

  6. HDU 2485 Destroying the bus stations

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

  7. Destroying the bus stations HDU - 2485(最小割点)

    题意: 就是求最小割点 解析: 正向一遍spfa 反向一遍spfa  然后遍历每一条边,对于当前边 如果dis1[u] + dis2[v] + 1 <= k 那么就把这条边加入到网络流图中, 每 ...

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

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

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

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

随机推荐

  1. FS,FT,DFS,DTFT,DFT,FFT的联系和区别

    DCT变换的原理及算法 文库介绍 对于初学数字信号处理(DSP)的人来说,这几种变换是最为头疼的,它们是数字信号处理的理论基础,贯穿整个信号的处理. 学习过<高等数学>和<信号与系统 ...

  2. Tkinter教程之Canvas篇(1)

    本文转载自:http://blog.csdn.net/jcodeer/article/details/1811803 '''Tkinter教程之Canvas篇(1)'''# 提供可以用来进行绘图的Co ...

  3. WinForm编程时窗体设计器中ComboBox控件大小的设置

    问题描述: 在VS中的窗体设计器中拖放一个ComboBox控件后想调整控件的大小.发现在控件上用鼠标只能拖动宽度(Width)无法拖动(Height). 解决过程: 1.控件无法拖动,就在属性窗口中设 ...

  4. 解开发者之痛:中国移动MySQL数据库优化最佳实践(转)

    开源数据库MySQL比较容易碰到性能瓶颈,为此经常需要对MySQL数据库进行优化,而MySQL数据库优化需要运维DBA与相关开发共同参与,其中MySQL参数及服务器配置优化主要由运维DBA完成,开发则 ...

  5. iOS本地数据存取

    应用沙盒 1)每个iOS应用都有自己的应用沙盒(应用沙盒就是文件系统目录),与其他文件系统隔离.应用必须待在自己的沙盒里,其他应用不能访问该沙盒 2)应用沙盒的文件系统目录,如下图所示(假设应用的名称 ...

  6. Java封装 properties文件操作

    /** * Prop. Prop can load properties file from CLASSPATH or File object. */ public class Prop { priv ...

  7. javascript中数组的迭代等操作

  8. HDU 1078 FatMouse and Cheese (记忆化搜索)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1078 老鼠初始时在n*n的矩阵的(0 , 0)位置,每次可以向垂直或水平的一个方向移动1到k格,每次移 ...

  9. Bootstrap迁移系列 - Navbar

    在V2.3.2版本中一个标准的导航栏模版如下: <div class="navbar"> <div class="navbar-inner"& ...

  10. (转)HTML5实战与剖析之触摸事件(touchstart、touchmove和touchend)

    HTML5中新添加了很多事件,但是由于他们的兼容问题不是很理想,应用实战性不是太强,所以在这里基本省略,咱们只分享应用广泛兼容不错的事件,日后随着兼容情况提升以后再陆续添加分享.今天为大家介绍的事件主 ...