hdu 4289 Control
来源:互联网 发布:linux telnet root 编辑:程序博客网 时间:2024/06/04 19:45
Control
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 698 Accepted Submission(s): 330
Problem Description
You, the head of Department of Security, recently received a top-secret information that a group of terrorists is planning to transport some WMD1 from one city (the source) to another one (the destination). You know their date, source and destination, and they are using the highway network.
The highway network consists of bidirectional highways, connecting two distinct city. A vehicle can only enter/exit the highway network at cities only.
You may locate some SA (special agents) in some selected cities, so that when the terrorists enter a city under observation (that is, SA is in this city), they would be caught immediately.
It is possible to locate SA in all cities, but since controlling a city with SA may cost your department a certain amount of money, which might vary from city to city, and your budget might not be able to bear the full cost of controlling all cities, you must identify a set of cities, that:
* all traffic of the terrorists must pass at least one city of the set.
* sum of cost of controlling all cities in the set is minimal.
You may assume that it is always possible to get from source of the terrorists to their destination.
------------------------------------------------------------
1 Weapon of Mass Destruction
The highway network consists of bidirectional highways, connecting two distinct city. A vehicle can only enter/exit the highway network at cities only.
You may locate some SA (special agents) in some selected cities, so that when the terrorists enter a city under observation (that is, SA is in this city), they would be caught immediately.
It is possible to locate SA in all cities, but since controlling a city with SA may cost your department a certain amount of money, which might vary from city to city, and your budget might not be able to bear the full cost of controlling all cities, you must identify a set of cities, that:
* all traffic of the terrorists must pass at least one city of the set.
* sum of cost of controlling all cities in the set is minimal.
You may assume that it is always possible to get from source of the terrorists to their destination.
------------------------------------------------------------
1 Weapon of Mass Destruction
Input
There are several test cases.
The first line of a single test case contains two integer N and M ( 2 <= N <= 200; 1 <= M <= 20000), the number of cities and the number of highways. Cities are numbered from 1 to N.
The second line contains two integer S,D ( 1 <= S,D <= N), the number of the source and the number of the destination.
The following N lines contains costs. Of these lines the ith one contains exactly one integer, the cost of locating SA in the ith city to put it under observation. You may assume that the cost is positive and not exceeding 107.
The followingM lines tells you about highway network. Each of these lines contains two integers A and B, indicating a bidirectional highway between A and B.
Please process until EOF (End Of File).
The first line of a single test case contains two integer N and M ( 2 <= N <= 200; 1 <= M <= 20000), the number of cities and the number of highways. Cities are numbered from 1 to N.
The second line contains two integer S,D ( 1 <= S,D <= N), the number of the source and the number of the destination.
The following N lines contains costs. Of these lines the ith one contains exactly one integer, the cost of locating SA in the ith city to put it under observation. You may assume that the cost is positive and not exceeding 107.
The followingM lines tells you about highway network. Each of these lines contains two integers A and B, indicating a bidirectional highway between A and B.
Please process until EOF (End Of File).
Output
For each test case you should output exactly one line, containing one integer, the sum of cost of your selected set.
See samples for detailed information.
See samples for detailed information.
Sample Input
5 65 35234121 55 42 32 44 32 1
Sample Output
3
Source
2012 ACM/ICPC Asia Regional Chengdu Online
代码:
#include<cstdio>#include<cstring>const int N=405;const int M=80005;const int INF=0x7fffffff;bool map[N][N];int n,s,t,m,tol;int head[N],arc[N],pre[N],dis[N],gap[N];struct node{ int y,f,nxt;}edge[M];void add(int x,int y,int f){ edge[tol].y=y; edge[tol].f=f; edge[tol].nxt=head[x]; head[x]=tol++; edge[tol].y=x; edge[tol].f=0; edge[tol].nxt=head[y]; head[y]=tol++;}void sap(){ memset(dis,0,sizeof(dis)); memset(gap,0,sizeof(gap)); memcpy(arc,head,sizeof(dis)); gap[0]=n; int ans=0,arg=INF,u=pre[s]=s; while(dis[s]<n) {L: for(int &i=arc[u];i!=-1;i=edge[i].nxt) { int v=edge[i].y; if(edge[i].f&&dis[u]==dis[v]+1) { if(arg>edge[i].f)arg=edge[i].f; pre[v]=u; u=v; if(v==t) { ans+=arg; for(u=pre[u];v!=s;v=u,u=pre[u]) { edge[arc[u]].f-=arg; edge[arc[u]^1].f+=arg; } arg=INF; } goto L; } } int min=n; for(int i=head[u];i!=-1;i=edge[i].nxt) { int v=edge[i].y; if(edge[i].f&&min>dis[v]) { arc[u]=i; min=dis[v]; } } if(--gap[dis[u]]==0)break; dis[u]=min+1; gap[dis[u]]++; u=pre[u]; } printf("%d\n",ans);}int main(){ int i; while(~scanf("%d%d",&n,&m)) { scanf("%d%d",&s,&t); t+=n; memset(head,-1,sizeof(head)); tol=0; int x,y; for(i=1;i<=n;i++) { scanf("%d",&x); add(i,i+n,x); } while(m--) { scanf("%d%d",&x,&y); add(x+n,y,INF); add(y+n,x,INF); } n*=2; sap(); } return 0;}
- hdu 4289 Control
- HDU 4289 Control
- hdu 4289 Control
- HDU 4289 Control
- HDU-4289 Control
- HDU 4289 Control
- 最大流:HDU-4289(CONTROL)
- 【HDU】4289 Control 最大流
- 【最小割】HDU 4289 Control
- hdu 4289 Control (最小割)
- hdu 4289 Control (最大流)
- HDU 4289 Control 网络流
- HDU 4289 Control 最大流
- Control HDU
- Control HDU
- HDU 4289 Control(拆点,最大流)
- hdu 4289 Control (最大流)
- HDU 4289 Control(最小割)
- c++继承中的内存布局
- Objective-C 一些很基础的总结
- 合并两个顺序存储结构的线性表...
- 杂1
- 视频笔记1
- hdu 4289 Control
- 关于set_new_handler
- 坚持
- 运用ImageButton编写选择头像小程序
- Oracle的逻辑结构(表空间、段、区间、块)——Oracle数据块
- hdu 4288 Coder
- PS CS4抽出滤镜抠图小技巧
- BigBlueButton mysql修改为postgresql or oracle
- 真彩色制式下IplImage转成CBitmap格式