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.但是在网络流中我们只能直接限制边的容量.所以需要拆点来完成 ...
随机推荐
- Windows服务-手把手带你体验
Microsoft Windows 服务(即,以前的 NT 服务)使您能够创建在它们自己的 Windows 会话中可长时间运行的可执行应用程序.这些服务可以在计算机启动时自动启动,可以暂停和重新启动而 ...
- The First Pig Task
The First Pig Program 环境: Hadoop-1.1.2 pig-0.11.1 linux系统为CentOS6.4 jdk1.6 在伪分布 ...
- 【Hadoop学习】HDFS 短路本地读
Hadoop版本:2.6.0 本文系从官方文档翻译而来,转载请尊重译者的工作,注明以下链接: http://www.cnblogs.com/zhangningbo/p/4146296.html 背景 ...
- Hellow world!
其实一年前开始就有了些许开篇技术博客的想法,一直觉得写这些的人都一定好牛×.现刚毕业,我也是时候朝牛×之路迈进了.当然,我才刚入门不久,前路漫漫,需一步一脚印,先打算把平常遇到的一些问题与关注的东西都 ...
- CodeForces 567A Gerald is into Art
http://codeforces.com/problemset/problem/567/A A. Lineland Mail time limit per test 3 seconds memory ...
- [C语言 - 2] C语言变量
A.变量的作用域: 1.局部变量:在函数或者代码块内部定义的变量 作用域:从定义处到代码块结束 生命周期:从定义处分配控件,代码块结束后被回收 局部变量没有默认值,要自己初始化 2.全局变量:在函 ...
- C#Windows窗体界面设计_01_绘制三角函数_附强制类型转换
binzhouweichao@163.com 今天开始学习C#windows窗体界面设计. 首先说一下类型转换. 参考http://www.csharpwin.com/csharpspace/6848 ...
- java tools: jmap
SYNOPSIS jmap [ option ] pid click here to see detail DESCRIPTION jmap prints shared object memory m ...
- cookie 编码问题
问题描述: Control character in cookie value or attribute. 解决方案: 1.前台编码 encodeURIComponent(str) 2.后台解码 原 ...
- Enterprise Library 服务问题
在使用Enterprise Library而没有注册服务的时候会出现这样的问题,"Editing Post "Failed to create instances of perfo ...