Destroying the bus stations
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 1832 | Accepted: 595 |
Description
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
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
Sample Input
- 5 7 3
- 1 3
- 3 4
- 4 5
- 1 2
- 2 5
- 1 4
- 4 5
- 0 0 0
Sample Output
- 2
大神的标程
- #include <iostream>
- #include <cstring>
- using namespace std;
- const int maxm=;
- const int maxn=;
- struct aaa
- {
- int s,f,next;
- };
- aaa c[maxm];
- int sta[maxn],fa[maxn],zh[maxn];
- int d[maxn][maxn],e[maxn];
- bool b[maxn];
- int n,m,now,tot;
- bool goal;
- void ins(int s,int f)
- {
- now++;
- c[now].s=s,c[now].f=f;c[now].next=sta[s],sta[s]=now;
- }
- void bfs()
- {
- int i,c1,op,k,t;
- c1=,op=;
- for(i=;i<=n;i++)
- fa[i]=;
- zh[]=;
- fa[]=-;
- while(c1<op)
- {
- c1++,k=zh[c1];
- for(t=sta[k];t;t=c[t].next)
- if(b[c[t].f]&&fa[c[t].f]==)
- {
- zh[++op]=c[t].f;
- fa[c[t].f]=c[t].s;
- if(c[t].f==n) break;
- }
- if(fa[n]) break;
- }
- }
- void dfs(int deep)
- {
- int i,c1,op,l,k;
- if(goal) return;
- bfs();
- if(fa[n]==)
- {
- goal=true;return;
- }
- l=;
- for(k=n;k>;k=fa[k])
- l++,d[deep][l]=k;
- if(l>m)
- { goal=true;
- return;
- }
- if(deep>tot) return;
- for(i=;i<=l;i++)
- {
- b[d[deep][i]]=false;
- if(e[d[deep][i]]==) dfs(deep+);
- b[d[deep][i]]=true;
- e[d[deep][i]]++;
- }
- for(i=;i<=l;i++)
- e[d[deep][i]]--;
- }
- int make()
- {
- int i,j;
- goal=false;
- for(i=;i<=n;i++)
- {
- tot=i;
- for(j=;j<=n;j++)
- b[j]=true;
- memset(e,,sizeof(e));
- dfs();
- if(goal) return i;
- }
- return n;
- }
- int main()
- {
- int i,s,f,g;
- while(true)
- {
- cin>>n>>g>>m;
- if(n==) break;
- memset(sta,,sizeof(sta));
- now=;
- for(i=;i<=g;i++)
- {
- cin>>s>>f;
- ins(s,f);
- }
- cout<<make()<<endl;
- }
- return ;
- }
Destroying the bus stations的更多相关文章
- HDUOJ----2485 Destroying the bus stations(2008北京现场赛A题)
Destroying the bus stations ...
- 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 ...
- 图论--网络流--最小割 HDU 2485 Destroying the bus stations(最短路+限流建图)
Problem Description Gabiluso is one of the greatest spies in his country. Now he's trying to complet ...
- POJ 3921 Destroying the bus stations 沿着最短路迭代加深搜索
题目:给出一个图,问最少删除多少个点,使得从点1到点n经过的点数超过k个. 分析: 上网搜了一下,发现很多人用网络流做的,发现我不会.再后来看到这篇说网络流的做法是错的,囧. 后来发现点数有点少,直接 ...
- HDU 2485 Destroying the bus stations (IDA*+ BFS)
传送门:http://acm.hdu.edu.cn/showproblem.php?pid=2485 题意:给你n个点,m条相连的边,问你最少去掉几个点使从1到n最小路径>=k,其中不能去掉1, ...
- HDU 2485 Destroying the bus stations
2015 ACM / ICPC 北京站 热身赛 C题 #include<cstdio> #include<cstring> #include<cmath> #inc ...
- Destroying the bus stations HDU - 2485(最小割点)
题意: 就是求最小割点 解析: 正向一遍spfa 反向一遍spfa 然后遍历每一条边,对于当前边 如果dis1[u] + dis2[v] + 1 <= k 那么就把这条边加入到网络流图中, 每 ...
- HDU 2485 Destroying the bus stations(费用流)
http://acm.hdu.edu.cn/showproblem.php?pid=2485 题意: 现在要从起点1到终点n,途中有多个车站,每经过一个车站为1时间,现在要在k时间内到达终点,问至少要 ...
- hdu 2485 Destroying the bus stations 最小费用最大流
题意: 最少需要几个点才能使得有向图中1->n的距离大于k. 分析: 删除某一点的以后,与它相连的所有边都不存在了,相当于点的容量为1.但是在网络流中我们只能直接限制边的容量.所以需要拆点来完成 ...
随机推荐
- FS,FT,DFS,DTFT,DFT,FFT的联系和区别
DCT变换的原理及算法 文库介绍 对于初学数字信号处理(DSP)的人来说,这几种变换是最为头疼的,它们是数字信号处理的理论基础,贯穿整个信号的处理. 学习过<高等数学>和<信号与系统 ...
- Tkinter教程之Canvas篇(1)
本文转载自:http://blog.csdn.net/jcodeer/article/details/1811803 '''Tkinter教程之Canvas篇(1)'''# 提供可以用来进行绘图的Co ...
- WinForm编程时窗体设计器中ComboBox控件大小的设置
问题描述: 在VS中的窗体设计器中拖放一个ComboBox控件后想调整控件的大小.发现在控件上用鼠标只能拖动宽度(Width)无法拖动(Height). 解决过程: 1.控件无法拖动,就在属性窗口中设 ...
- 解开发者之痛:中国移动MySQL数据库优化最佳实践(转)
开源数据库MySQL比较容易碰到性能瓶颈,为此经常需要对MySQL数据库进行优化,而MySQL数据库优化需要运维DBA与相关开发共同参与,其中MySQL参数及服务器配置优化主要由运维DBA完成,开发则 ...
- iOS本地数据存取
应用沙盒 1)每个iOS应用都有自己的应用沙盒(应用沙盒就是文件系统目录),与其他文件系统隔离.应用必须待在自己的沙盒里,其他应用不能访问该沙盒 2)应用沙盒的文件系统目录,如下图所示(假设应用的名称 ...
- Java封装 properties文件操作
/** * Prop. Prop can load properties file from CLASSPATH or File object. */ public class Prop { priv ...
- javascript中数组的迭代等操作
- HDU 1078 FatMouse and Cheese (记忆化搜索)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1078 老鼠初始时在n*n的矩阵的(0 , 0)位置,每次可以向垂直或水平的一个方向移动1到k格,每次移 ...
- Bootstrap迁移系列 - Navbar
在V2.3.2版本中一个标准的导航栏模版如下: <div class="navbar"> <div class="navbar-inner"& ...
- (转)HTML5实战与剖析之触摸事件(touchstart、touchmove和touchend)
HTML5中新添加了很多事件,但是由于他们的兼容问题不是很理想,应用实战性不是太强,所以在这里基本省略,咱们只分享应用广泛兼容不错的事件,日后随着兼容情况提升以后再陆续添加分享.今天为大家介绍的事件主 ...