fzu1844 Earthquake Damage (网络流 最大流最小割/ISAP)
来源:互联网 发布:centos 开机启动脚本 编辑:程序博客网 时间:2024/06/07 19:59
[Submit] [Go Back] [Status]
Description
Open Source Tools help earthquake researchers stay a step ahead. Many geological research facilities around the world use or are in the process of developing open source software and applications designed to interpret and share information with other researchers. For example, OpenSees is an open source software framework for developing apps that help understand what happens to structures during and after earthquakes to help engineers design stronger buildings. Researchers are also using OpenSees to understand the potential ill-effects of seismic activity on viaducts and bridges.
China has had an earthquake that has struck Sichuan Province on Monday 12 May 2008!
The earthquake has damaged some of the cities so that they are unpassable. Remarkably, after repairing by Chinese People's Liberation Army, all the driveways between cities were fixed.
As usual, Sichuan Province is modeled as a set of P (1 <= P <= 3,000) cities conveniently numbered 1..P which are connected by a set of C (1 <= C <= 20,000) non-directional driveways conveniently numbered 1..C. Driveway i connects city a_i and b_i (1 <= a_i <= P; 1 <= b_i <= P). Driveway might connect a_i to itself or perhaps might connect two cities more than once. The Crisis Center is located in city 1.
A total of N (1 <= N <= P) survivors (in different cities) sequentially contacts Crisis Center via moobile phone with an integer message report_j (2 <= report_j <= P) that indicates that city report_j is undamaged but that the calling survivor is unable to return to the Crisis Center from city report_j because he/she could not find a path that does not go through damaged city.
After all the survivors report in, determine the minimum number of cities that are damaged.
Input
Input consists of several testcases. The format of each case as follow:
Output
For each testcase, output a line with one number, the minimum number of damaged cities.
Sample Input
5 5 21 22 33 52 44 545
Sample Output
1
Hint
#include <cstdio>#include <cstring>#include <algorithm>const long M=6100;const long NE=121000;const long inf=1<<30;struct ISAP{ long head[M],next[NE],to[NE],cap[NE],cnt; long dist[M],gap[M],pre[M],cur[M],n; void init_edge(long x){ n=x; memset(head,-1,sizeof(head)); cnt=0; } void add_edge(long u,long v,long c){ next[cnt]=head[u]; to[cnt]=v; cap[cnt]=c; head[u]=cnt++; next[cnt]=head[v]; to[cnt]=u; cap[cnt]=0; head[v]=cnt++; } long MaxFlow(long s,long t){ long maxflow=0,flow=inf,flag; long u,v; for (long i=0;i<=n;++i){ dist[i]=gap[i]=0; cur[i]=head[i]; } u=pre[s]=s; gap[0]=n; while (dist[s]<n){ flag=0; for (long &i=cur[u];i!=-1;i=next[i]){ v=to[i]; if (cap[i]>0 && dist[u]==dist[v]+1){ flow=std::min(flow,cap[i]); pre[v]=u; u=v; flag=1; if (v==t){ maxflow+=flow; while (u!=s){ u=pre[u]; cap[cur[u]]-=flow; cap[cur[u]^1]+=flow; } flow=inf; } break; } } if (flag) continue; long min_dist=n; for (long i=head[u];i!=-1;i=next[i]){ v=to[i]; if (cap[i]>0 && dist[v]<min_dist){ min_dist=dist[v]; cur[u]=i; } } if ((--gap[dist[u]])==0) break; gap[dist[u]=min_dist+1]++; u=pre[u]; } return maxflow; }}G;int main(){ long p,c,n,vis[M]; while (~scanf("%d%d%d",&p,&c,&n)){long s=1,t=2*p+1; G.init_edge(t); memset(vis,0,sizeof(vis)); while (c--){ long u,v; scanf("%d%d",&u,&v); G.add_edge(u+p,v,inf); G.add_edge(v+p,u,inf); } while (n--){ long x; scanf("%d",&x); vis[x]=1; G.add_edge(x,t,inf); }G.add_edge(1,1+p,inf); for (long i=2;i<=p;++i) if (!vis[i]) G.add_edge(i,i+p,1); else G.add_edge(i,i+p,inf); printf("%d\n",G.MaxFlow(s,t)); } return 0;}
- fzu1844 Earthquake Damage (网络流 最大流最小割/ISAP)
- 网络流模版(ISAP)/最大流最小割定理 poj 3469
- 计蒜之道 初赛 第一场 题解 dp 高效 网络流 最小割 最大流 ISAP 模板
- BZOJ_P2561 最小生成树(网络流+最大流ISAP)
- 网络流最大流最小割算法
- 网络流最大流最小割算法
- 网络流 最小割最大流定理
- 网络的最大流最小割定理
- isap算法网络最大流
- 网络流(最小割最大流)【POJ3469】
- 网络流(最小割最大流)【POJ3308】
- 网络流(最大流,最小割)基础入门详解
- 求最大网络流(最小割)总结
- 【BZOJ 1585】 [Usaco2009 Mar]Earthquake Damage 2 地震伤害 最小割
- bzoj 1585: [Usaco2009 Mar]Earthquake Damage 2 地震伤害 最小割
- 最大流/最小割
- 最大流最小割
- 最大流最小割
- HDU 4604 Deque
- Android Color
- 网络流
- poj2983 Is the Information Reliable?
- CALayer层次
- fzu1844 Earthquake Damage (网络流 最大流最小割/ISAP)
- C#扩展方法初探
- SQL语句大全
- C C++ 编程Editor 选择
- 在C#中使用Response.write返回的内容不要HTML
- 网络流演示
- python解析XML文档
- UVa 10392: Factoring Large Numbers
- dancelinks(重复) 模板