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 ...
随机推荐
- mysql中bigint、int、mediumint、smallint 和 tinyint的取值范围
mysql数据库设计,其中,对于数据性能优化,字段类型考虑很重要,搜集了些资料,整理分享出来,这篇为有关mysql整型bigint.int.mediumint.smallint 和 tinyint的语 ...
- 2016-2017 ACM-ICPC, NEERC, Southern Subregional Contest (Online Mirror, ACM-ICPC Rules, Teams Preferred) 几道简单题的题解
A. Toda 2 题意:给你n个人,每个人的分数是a[i],每次可以从两个人到五个人的使得分数减一,使得最终的分数相等: 思路:假设答案为m:每个人的分数与答案m的差值为d[i],sum为d[i]的 ...
- C#线程系列讲座(5):同步技术之Monitor
在上一讲介绍了使用lock来实现线程之间的同步.实际上,这个lock是C#的一个障眼法,在C#编译器编译lock语句时,将其编译成了调用Monitor类.先看看下面的C#源代码: public sta ...
- PhpStorm的注册码、Key
下面是PhpStorm的注册码.Key,其license由用户名和License值组成. User name: EMBRACE License key: ===== LICENSE BEGIN === ...
- JQery 中的 $(".bb:eq(1)") eq () 解释。。
这是一段代码: <div id="bb">a</div> <div id="bb">b</div> <di ...
- [转]ubuntu环境变量配置文件
参考网址:http://www.bkjia.com/Linuxjc/1008127.html Ubuntu通常使用的几个配置文件主要有下面这几个: /etc/environment./etc/prof ...
- CentOS的包/库的找的地方
1. http://pkgs.org/ 在这个网站里面 搜索相应的 包名,看能不能找到. 2. http://rpm.pbone.net/ 在这个网站里面 搜索相应的 包名,看能不能找到. 3.
- Dolphin for Android(v11.5.1[Jetpack:内置])
1. 下载的地址为“http://www.techspot.com/downloads/5927-dolphin-browser-for-android.html” ZC: 由于 Google Pla ...
- Codeforces 713C Sonya and Problem Wihtout a Legend
题意:给一个序列,可以进行若干次操作,每次操作选择一个数让它+1或-1,问最少要几次操作使得序列变为严格单调递增序列. 题解:首先考虑非严格递增序列,则每个数字最终变成的数字一定是该数组中的某个数.那 ...
- 01 Developing Successful Oracle Applications
varchar2 类型定义时, 个人认为应该选择byte 类型, 即 varchar2(20), oracle 支持的最大的字符串是 varchar2(4000), 同时, 个人认为, 当你定义一个v ...