Destroying the bus stations
Time limit:4000/2000 MS (java/others) Memory limit:32768/32768 K (java/others)
Total submission (s): 2492 Accepted Submission (s): 813
problem DescriptionGabiluso is one of the greatest spies in his country. Now he's trying to complete a "impossible" mission-----to make it slow for the army of city Colugu to reach the airport . City Colugu have n bus stations and M roads. Each road connects the bus stations directly, and all roads is one, the 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 is more than one road between bus stations. If A bus station was destroyed, all roads connecting the station would become no use. What's gabiluso needs to do are 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 is numbered from 1 to N. The "the" bus station was in the barrack and the No. N Station was in the airport. The army always set off from the No. 1 station.
Station and No. N station can ' t is destroyed because of the heavy guard. Of course there is no road from the airport to No. N Station.
Please help Gabiluso to calculate the minimum number of bus stations he must destroy to complete his mission.
InputThere is 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 this there is a road from Station No. s to Station No. f.
OutputFor each test case, output the minimum number of stations gabiluso must destroy.
Sample Input5 7 31 33 44 51 22 51 44 50 0 0
Sample Output2
SourceRegional Asia Beijing Problem solving: run the cost stream directly until the shortest path is greater than the K
1#include <bits/stdc++.h>2 using namespacestd;3 Const intINF =0x3f3f3f3f;4 Const intMAXN = -;5 structarc{6 intTo,flow,cost,next;7Arcintx =0,inty =0,intz =0,intNXT =-1){8to =x;9Flow =y;TenCost =Z; OneNext =NXT; A } -}e[maxn*MAXN]; - inthead[maxn],d[maxn],p[maxn],tot,s,t,n,m,k; the voidAddintUintVintFlowintCost ) { -E[tot] =arc (V,flow,cost,head[u]); -Head[u] = tot++; -E[tot] = arc (U,0,-cost,head[v]); +HEAD[V] = tot++; - } + BOOLSPFA () { Amemset (D,0x3f,sizeofd); atmemset (p,-1,sizeofp); -queue<int>Q; - BOOL inch[MAXN] = {}; - Q.push (S); -D[s] =0; - while(!Q.empty ()) { in intU =Q.front (); - Q.pop (); to inch[U] =false; + for(inti = Head[u]; ~i; i =E[i].next) { - if(E[i].flow && d[e[i].to] > D[u] +e[i].cost) { theD[e[i].to] = D[u] +E[i].cost; *P[e[i].to] =i; $ if(!inch[e[i].to]) {Panax Notoginseng inch[E[i].to] =true; - Q.push (e[i].to); the } + } A } the } + returnP[t] >-1&& D[t] <=K; - } $ intSolveintRET =0){ $ while(SPFA ()) { - intMinF =INF; - for(inti = p[t]; ~i; i = p[e[i^1].to]) theMinF =min (minf,e[i].flow); - for(inti = p[t]; ~i; i = p[e[i^1].to]) {WuyiE[i].flow-=MinF; thee[i^1].flow + =MinF; - } WuRET + =MinF; - } About returnret; $ } - intMain () { - intu,v; - while(SCANF ("%d%d%d", &n,&m,&k) = =3&& (n| | m| |k)) { Amemset (head,-1,sizeofhead); +tot =0; the for(inti =1; I <= N; ++i) Add (I,i + N,1,0); - for(inti =0; I < m; ++i) { $scanf"%d%d",&u,&v); theAdd (U + n,v,inf,1); the } theS =1+N; theT =N; -printf"%d\n", Solve ()); in } the return 0; the}
View Code
HDU 2485 destroying the bus stations