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. C语言相关图书推荐

    C Primer Plus(第5版 中文版) 作      者 [美] 普拉塔(Prata S.) 著:云巅工作室 编 出 版 社 人民邮电出版社 出版时间 2005-02-01 版      次 1 ...

  2. [转]Ubuntu下GitHub的使用

    转自Pythoner 本文将对Ubuntu下Git的安装,以及如何连接GitHub进行讲解. 1.环境 OS: Ubuntu13.04 64bitsGit: 1.8.1.2 2.Git安装 执行如下命 ...

  3. MySQL锁问题最佳实践

    最近一段时间处理了较多锁的问题,包括锁等待导致业务连接堆积或超时,死锁导致业务失败等,这类问题对业务可能会造成严重的影响,没有处理经验的用户往往无从下手.下面将从整个数据库设计,开发,运维阶段介绍如何 ...

  4. Apache Spark Shark的简介

    Shark是构建在Spark和Hive基础之上的数据仓库. 目前,Shark已经完成学术使命,终止开发,但其架构和原理仍具有借鉴意义. 它提供了能够查询Hive中所存储数据的一套SQL接口,兼容现有的 ...

  5. CoffeeScript学习(1)——Quick Start

    什么是CoffeeScript CoffeeScript 是一门编译到 JavaScript 的小巧语言. 在 Java 般笨拙的外表下, JavaScript 其实有着一颗华丽的心脏. Coffee ...

  6. Android实例-屏幕操持常亮(XE8+小米2)

    相关资料: http://www.bubuko.com/infodetail-163304.html 结果: 1.打开权限Wake lock为True. 第三方单元: unit Android.JNI ...

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

  8. properties.load(in); 引出的中文乱码问题

    /** * Reads a property list (key and element pairs) from the input byte stream. * The input stream i ...

  9. iOS开发60分钟入门

    原文:https://github.com/qinjx/30min_guides/blob/master/ios.md 本文面向已有其它语言(如Java,C,PHP,Javascript)编程经验的i ...

  10. Intel HAXM

    Hardware Accelerated Execution Manager的缩写. intel的硬件加速执行管理器,是一款可以使用英特尔虚拟化技术(VT)加快 Android* 开发速度的硬件辅助虚 ...