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是
 贴一下
代码:
 #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 ;
}
 
上一篇:图论(生成树):HDU 5631Rikka with Graph


下一篇:从PRISM开始学WPF(四)Prism-Module?