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
Problem 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
Source
此题是最大最小流/现在还在温习中....!
题意:
Gabiluso是
贴一下
代码:
1 #include<iostream>
2 #include<cstring>
3 #include<cstdio>
4 #include<cstdlib>
5 #include<algorithm>
6
7 using namespace std;
8
9 const int maxm = 10005 ; //最大边数
10 const int maxn = 105 ; //最大点数
11
12 struct aaa
13 {
14 int s,f,next ;
15 };
16
17 aaa c[maxm];
18 int sta[maxn],fa[maxn],zh[maxn];
19 int d[maxn][maxn],e[maxn];
20 bool b[maxn];
21 int n,m,now,tot;
22 bool goal;
23
24 void ins(int s ,int f) //创建邻接表
25 {
26 now++;
27 c[now].s=s;
28 c[now].f=f;
29 c[now].next=sta[s];
30 sta[s]=now;
31 }
32
33 void bfs()
34 {
35 int i,cl,op,k,t;
36 cl=0;op=1;
37 for(i=1;i<=n ;i++) fa[i]=0;
38 zh[1]=1;fa[1]=-1;
39 while(cl<op)
40 {
41 cl++;
42 k=zh[cl];
43 for( t=sta[k] ; t ; t=c[t].next )
44 if(b[c[t].f]&&fa[c[t].f]==0)
45 {
46 op++;
47 zh[op]=c[t].f;
48 fa[c[t].f]=c[t].s;
49 if(c[t].f==n) break;
50 }
51 if(fa[n]) break ;
52 }
53 }
54
55 void dfs(int deep)
56 {
57 int i,cl,op,l,k;
58 if(goal) return ;
59 bfs();
60 if(fa[n]==0)
61 {
62 goal=true ;
63 return ;
64 }
65 l=0;
66 for(k=n ;k>l ; k=fa[k])
67 {
68 l++;
69 d[deep][l]=k;
70 }
71 if(l>m)
72 {
73 goal=true;
74 return ;
75 }
76 if(deep>tot) return ;
77
78 for(i=2;i<=l;i++)
79 {
80 b[d[deep][i]]=false ;
81 if(e[d[deep][i]]==0) dfs(deep+1);
82 b[d[deep][i]]=true;
83 e[d[deep][i]]++;
84 }
85 for(i=2 ; i<=l ; i++ )
86 e[d[deep][i]]--;
87 }
88
89 int make()
90 {
91 int i,j;
92 goal= false;
93 for(i=0 ;i<=n ;i++)
94 {
95 tot=i;
96 for(j=1;j<=n ;j++) b[j]=true;
97 memset(e,0,sizeof(e));
98 dfs(1);
99 if(goal) return i;
100 }
101 return n;
102 }
103
104 int main()
105 {
106 int i,s,f,g;
107 while(1)
108 {
109 scanf("%d%d%d",&n,&g,&m);
110 if(n==0) break;
111 memset(sta,0,sizeof(sta));
112 now=0;
113 for(i=1; i<=g ;i++)
114 {
115 scanf("%d%d",&s,&f);
116 ins(s,f);
117 }
118 g=make();
119 printf("%dn",g);
120 }
121 return 0;
122 }
- 如何解决jQuery Validation针对动态添加的表单无法工作的问题?
- 数据结构 链表改进
- 数据结构 栈&队列
- 终端品牌域名过期被拍卖 价值六位数
- TensorFlow 深度学习笔记 TensorFlow实现与优化深度神经网络
- ASP.NET的路由系统:路由映射
- ASP.NET Core的配置(3): 将配置绑定为对象[上篇]
- ASP.NET的路由系统:URL与物理文件的分离
- 使用Excel分析CloudStack使用记录
- 卷积神经网络初探索
- TensorFlow 深度学习笔记 逻辑回归 实践篇
- 黑客是如何实施暴力破解的?
- Python的初学者你现在可以自己“看”到代码的运行了!
- ASP.NET Core的配置(3): 将配置绑定为对象[下篇]
- JavaScript 教程
- JavaScript 编辑工具
- JavaScript 与HTML
- JavaScript 与Java
- JavaScript 数据结构
- JavaScript 基本数据类型
- JavaScript 特殊数据类型
- JavaScript 运算符
- JavaScript typeof 运算符
- JavaScript 表达式
- JavaScript 类型转换
- JavaScript 基本语法
- JavaScript 注释
- Javascript 基本处理流程
- Javascript 选择结构
- Javascript if 语句
- Javascript if 语句的嵌套
- Javascript switch 语句
- Javascript 循环结构
- Javascript 循环结构实例
- Javascript 跳转语句
- Javascript 控制语句总结
- Javascript 函数介绍
- Javascript 函数的定义
- Javascript 函数调用
- Javascript 几种特殊的函数
- JavaScript 内置函数简介
- Javascript eval() 函数
- Javascript isFinite() 函数
- Javascript isNaN() 函数
- parseInt() 与 parseFloat()
- escape() 与 unescape()
- Javascript 字符串介绍
- Javascript length属性
- javascript 字符串函数
- Javascript 日期对象简介
- Javascript 日期对象用途
- Date 对象属性和方法
- Javascript 数组是什么
- Javascript 创建数组
- Javascript 数组赋值与取值
- Javascript 数组属性和方法
- [Maven][taglist-maven-plugin]告警[WARNING] Using legacy tag format
- [Maven][l10n-maven-plugin]告警[WARNING] No dictionary file under folder
- Python基础之多文件项目的演练
- Python中的命名空间和作用域(1)
- 浅谈Mybatis持久化框架在Spring、SSM、SpringBoot整合的演进及简化过程
- 玩转注册表,这几个windowsAPI函数就够了
- 施工专题第11篇:Python 包和模块使用总结
- Node.js-具有示例API的基于角色的授权教程
- 删库时,我后悔没早学会的数据库知识
- SwiftUI:使自定义类型符合 Comparable 协议
- 【CCF】线性分类器
- 计数二进制子串
- 6个实例详解如何把if-else代码重构成高质量代码
- leetcode201场周赛
- ASP.NET MVC+LayUI视频上传