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

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的更多相关文章

  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. stl+模拟 CCF2016 4 路径解析

    // stl+模拟 CCF2016 4 路径解析 // 一开始题意理解错了.... #include <iostream> #include <string> #include ...

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

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

  3. ubuntu java jdk安装及环境变量设置

    1.下载jdk1.7.0_79 (32位操作系统)jdk-7u79-linux-i586.tar.gz (64位操作系统)jdk-7u79-linux-x64.tar.gz http://www.or ...

  4. 一条scan查询把HBase集群干趴下

    最近在给公司搭建CDH集群,在测试集群性能时,写了一条简单的scan查询语句竟然把hbase集群的所有regionserver干趴下了.这让我云里雾里的飘飘然. 背景介绍 CDH集群,2台主节点.3台 ...

  5. 【hbase】使用thrift with python 访问HBase

    HBase 版本: 0.98.6 thrift   版本: 0.9.0 使用 thrift client with python 连接 HBase 报错: Traceback (most recent ...

  6. nodejs + socket.io + redis 新手上路

    最近要更新网站架构了,决定转入 nodejs + socket.io + redis 方式. 战斗刚开始: 网上的文章太松散,我根据各个网友的分享进行整理 ,让大家可以方便上手. 进入node.js之 ...

  7. 第二百四十一天 how can I 坚持

    今天去了趟小米之家,红米note3感觉还好吧.小米,希望不会令人失望啊,很看好的,应该不算是米粉吧. 腾讯课堂. hadoop. 摄影. 没有真正的兴趣啊,一心只想着玩,什么事真正的兴趣,就是无时无刻 ...

  8. homework-07

    终于等到了一次难度相对比较小的问题,只要读完提问题就好,但又不得不说自己真的很菜,且不说C++掌握的不好,连英文也比较差,导致读的非常吃力,不过我还是坚持读完了四篇英文文章,大致意思是可以了解的,但是 ...

  9. Delimiter must not be alphanumeric or backslash 问题及解决

    Warning: preg_match() [function.preg-match]: Delimiter must not be alphanumeric or backslash in 正则表达 ...

  10. Linux优化之IO子系统监控与调优

    Linux优化之IO子系统 作为服务器主机来讲,最大的两个IO类型 : 1.磁盘IO 2.网络IO 这是我们调整最多的两个部分所在 磁盘IO是如何实现的 在内存调优中,一直在讲到为了加速性能,linu ...