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.但是在网络流中我们只能直接限制边的容量.所以需要拆点来完成 ...
随机推荐
- bzoj 1458 士兵占领(最大流)
[题意] n行m列,第i行必须放L[i],第j列必须放C[j],有障碍格,求满足条件至少需要放多少. [思路] 至少放多少等价于最多不放多少. 对行列分别建XY点,则连边(S,Xi,a)(Yi,T,b ...
- HDU5634 Rikka with Phi 线段树
// HDU5634 Rikka with Phi 线段树 // 思路:操作1的时候,判断一下当前区间是不是每个数都相等,在每个数相等的区间上操作.相当于lazy,不必更新到底. #include & ...
- Tkinter教程之Checkbutton篇
本文转载自:http://blog.csdn.net/jcodeer/article/details/1811306 #Tkinter教程之Checkbutton篇#Checkbutton又称为多选按 ...
- 02《老罗Android开发视频教程》第二集:android系统框架的介绍
- Java中快如闪电的线程间通讯
这个故事源自一个很简单的想法:创建一个对开发人员友好的.简单轻量的线程间通讯框架,完全不用锁.同步器.信号量.等待和通知,在Java里开发一个轻量.无锁的线程内通讯框架:并且也没有队列.消息.事件或任 ...
- 软件工程 --- Pair Project: Elevator Scheduler [电梯调度算法的实现和测试] [附加题]
软件工程 --- Pair Project: Elevator Scheduler [电梯调度算法的实现和测试] [附加题] 首先,在分组之前,我和室友薛亚杰已经详细阅读了往届学长的博客,认为电梯调度 ...
- ocp 1Z0-051 71-105题解析
71. Which arithmeticoperations can be performed on a column by using a SQL function that is builtint ...
- Mysql创建、删除用户
1.新建用户 //登录MYSQL@>mysql -u root -p@>密码//创建用户mysql> insert into mysql.user(Host,User,Passwor ...
- 转载Agile Development 敏捷软件开发介绍
转载原地址: http://blog.csdn.net/wayne_ran/article/details/1601008 敏捷开发(agile development)是一种以人为核心.迭代.循序渐 ...
- 使用PUT方法上传文件无法工作原因分析
现象 在Spring Framework中,使用HTTP的PUT方法上传文件时,在服务器端发现Multipart参数为空. 原因 Spring中的StandardServletMultipartRes ...