HDUOJ----2485 Destroying the bus stations(2008北京现场赛A题)
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
Please help Gabiluso to calculate the minimum number of bus stations he must destroy to complete his mission.
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.
#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题)的更多相关文章
- HDUOJ-------2493Timer(数学 2008北京现场赛H题)
Timer Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Subm ...
- HDUOJ--------A simple stone game(尼姆博弈扩展)(2008北京现场赛A题)
A simple stone game ...
- 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 ...
- 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(费用流)
http://acm.hdu.edu.cn/showproblem.php?pid=2485 题意: 现在要从起点1到终点n,途中有多个车站,每经过一个车站为1时间,现在要在k时间内到达终点,问至少要 ...
- HDU 2485 Destroying the bus stations
2015 ACM / ICPC 北京站 热身赛 C题 #include<cstdio> #include<cstring> #include<cmath> #inc ...
- hdu 2485 Destroying the bus stations 最小费用最大流
题意: 最少需要几个点才能使得有向图中1->n的距离大于k. 分析: 删除某一点的以后,与它相连的所有边都不存在了,相当于点的容量为1.但是在网络流中我们只能直接限制边的容量.所以需要拆点来完成 ...
- 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 ...
随机推荐
- linux 中 ll 命令如何让查询结果按时间升序或降序排序?
-t选项的功能是使输出的结果将以时间降序排列.如果希望按时间的升序排列,可以使用管道符将返回的结果传入tac命令.用法示例:查询当前目录的文件并以降序排列: ll -t查询当前目录的文件并以升序排列: ...
- js跨域及解决方案
本文出自:http://www.cnblogs.com/oneword/archive/2012/12/03/2799443.html 1.什么是跨域 我们经常会在页面上使用ajax请求访问其他服务器 ...
- 哈理工软件学院"兆方美迪"杯第六届程序设计大赛【高年级组】--决赛 题解
比赛链接:http://acm-software.hrbust.edu.cn/contest.php?cid=1082 A.好SB啊真是,还以为lis-数有多少个数不一样. #include < ...
- linux挂载共享文件夹
挂载windows共享目录或FTP: 方式一:包含密码 Shell代码 收藏代码 sudo mount //192.168.10.22/FTPServer /windows -o username=u ...
- react入门笔记
this.props.children是任何内嵌的元素 利用ref属性给子组件命名,this.refs引用组件,getDOMNode()获取本地的DOM元素,如: this.refs.author.g ...
- Python基础学习笔记(八)常用字典内置函数和方法
参考资料: 1. <Python基础教程> 2. http://www.runoob.com/python/python-dictionary.html 3. http://www.lia ...
- 2013/7/17 HNU_训练赛5
sgu 542 Gena vs Petya sgu 543 Cafe 题意:有N组人需要被分配到某些固定了人数的桌子上,其中ai表示第i组有多少个人,安排作为需要符合如下安排:某一组的人员不能够单独在 ...
- iOS - UIScrollView
前言 NS_CLASS_AVAILABLE_IOS(2_0) @interface UIScrollView : UIView <NSCoding> @available(iOS 2.0, ...
- JAVA 大数据内存耗用测试
JAVA 大数据内存耗用测试import java.lang.management.ManagementFactory;import java.lang.management.MemoryMXBean ...
- [转载] Linux下高并发socket最大连接数所受的各种限制
原文: http://mp.weixin.qq.com/s?__biz=MzAwNjMxNjQzNA==&mid=207772333&idx=1&sn=cfc8aadb422f ...