Destroying the bus stations

                                                                                    Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)

                                                                                                           Total Submission(s): 2072    Accepted Submission(s): 647

Problem 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
5 7 3
1 3
3 4
4 5
1 2
2 5
1 4
4 5
0 0 0
 
Sample Output
2
 
Source
 
此题是最大最小流/现在还在温习中....!
题意:
Gabiluso是
 贴一下
代码:

 #include<iostream>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<algorithm> 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,cl,op,k,t;
cl=;op=;
for(i=;i<=n ;i++) fa[i]=;
zh[]=;fa[]=-;
while(cl<op)
{
cl++;
k=zh[cl];
for( t=sta[k] ; t ; t=c[t].next )
if(b[c[t].f]&&fa[c[t].f]==)
{
op++;
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,cl,op,l,k;
if(goal) return ;
bfs();
if(fa[n]==)
{
goal=true ;
return ;
}
l=;
for(k=n ;k>l ; 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()
{
scanf("%d%d%d",&n,&g,&m);
if(n==) break;
memset(sta,,sizeof(sta));
now=;
for(i=; i<=g ;i++)
{
scanf("%d%d",&s,&f);
ins(s,f);
}
g=make();
printf("%d\n",g);
}
return ;
}
 

HDUOJ----2485 Destroying the bus stations(2008北京现场赛A题)的更多相关文章

  1. HDUOJ-------2493Timer(数学 2008北京现场赛H题)

    Timer Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Subm ...

  2. HDUOJ--------A simple stone game(尼姆博弈扩展)(2008北京现场赛A题)

    A simple stone game                                                                                  ...

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

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

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

  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(费用流)

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

  7. HDU 2485 Destroying the bus stations

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

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

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

  9. hdu-----2491Priest John's Busiest Day(2008 北京现场赛G)

    Priest John's Busiest Day Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Jav ...

随机推荐

  1. c++ socket 客户端库 socks5 客户端 RudeSocket™ Open Source C++ Socket Library

    介绍 一个c++ socket 客户端库 http://www.rudeserver.com/socket/index.html The RudeSocket™ Open Source C++ Soc ...

  2. 最大似然估计(MLE)与最小二乘估计(LSE)的区别

    最大似然估计与最小二乘估计的区别 标签(空格分隔): 概率论与数理统计 最小二乘估计 对于最小二乘估计来说,最合理的参数估计量应该使得模型能最好地拟合样本数据,也就是估计值与观测值之差的平方和最小. ...

  3. Find Current Job Openings For Oracle Forms & Reports

    Oracle Form & Reports developer jobs are always in demand, candidates who have Oracle D2k, Oracl ...

  4. Calling / Running a report in Oracle forms 10g / 11g

    Calling / Running a report in Oracle forms 10g / 11g Below is the procedure to call a report in Orac ...

  5. ajax请求、servlet返回json数据

    ajax请求.servlet返回json数据 1.方式一 response.setcontenttype("text/html;charset=utf-8"); response. ...

  6. hdu 1596(Floyd 变形)

    http://acm.hdu.edu.cn/showproblem.php?pid=1596 find the safest road Time Limit: 10000/5000 MS (Java/ ...

  7. 学习python得到方向与主体

    Python的主体内容大致可以分为以下几个部分: 面向过程.包括基本的表达式,if语句,循环,函数等.如果你有任何一个语言的基础,特别是C语言的基础,这一部分就是分分钟了解下Python规定的事.如果 ...

  8. 【FFT-快速傅立叶变换】

    HDU-1402 A * B Problem Plus 题意:给定两个整数,整数的长度最多能达到50000位,输出两个整数的乘积. 分析:题意非常的明了,一个惊世骇俗的想法是使用两个数组将整数保留起来 ...

  9. iOS 设置button中图文位置

    方法一. -(CGRect)imageRectForContentRect:(CGRect)contentRect {    return CGRectMake(self.width - kImage ...

  10. Android activity四种基本启动模式

    standard:默认的模式,每次启动会新创建一个activity对象 singleTop:在当前任务栈中,判断栈顶是否为当前的activity,如果是,就直接使用,如果不是,就会创建新的activi ...