hdoj--3491--Thieves(最小割点集)
来源:互联网 发布:西蒙智力量表软件 编辑:程序博客网 时间:2024/04/30 08:45
Thieves
Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others)Total Submission(s): 1535 Accepted Submission(s): 692
Problem Description
In the kingdom of Henryy, there are N (2 <= N <= 100) cities, with M (M <= 10000) two-direct ways connecting them.
A group of thieves from abroad plan to steal the metropolitan museum in city H (It has not been demolished). However, the brave, brilliant, bright police in the kingdom have known this plan long before, and they also plan to catch the thieves. The thieves are in the city S at present. The police try to catch them on their way from S to H. Although the thieves might travel this way by more than one group, our excellent police has already gather the statistics that the number of the people needed in city I (1<=I<=N) to arrest the thieves.
The police do not want to encounter the thieves in either city S or city H.
The police finish the task with the minimum number of people. Do you know the exact number?
A group of thieves from abroad plan to steal the metropolitan museum in city H (It has not been demolished). However, the brave, brilliant, bright police in the kingdom have known this plan long before, and they also plan to catch the thieves. The thieves are in the city S at present. The police try to catch them on their way from S to H. Although the thieves might travel this way by more than one group, our excellent police has already gather the statistics that the number of the people needed in city I (1<=I<=N) to arrest the thieves.
The police do not want to encounter the thieves in either city S or city H.
The police finish the task with the minimum number of people. Do you know the exact number?
Input
The first line contains an integer T (T <= 10), indicating the number of the test cases.
The first line of each test case has four integers: N, the number of the cities; M, the number of the roads; S (1<=S<=N), the label of city S; H (1<=T<=N, S≠H), the label of city H.
The second line contains N integers, indicating the number of people needed in each city. The sum of these N integers is less than 10000.
Then M lines followed, each containing two integers x and y, indicating that there is a two-direct roads between city x and y. Notices that no road between city S and H.
A blank line is followed after each test case.
The first line of each test case has four integers: N, the number of the cities; M, the number of the roads; S (1<=S<=N), the label of city S; H (1<=T<=N, S≠H), the label of city H.
The second line contains N integers, indicating the number of people needed in each city. The sum of these N integers is less than 10000.
Then M lines followed, each containing two integers x and y, indicating that there is a two-direct roads between city x and y. Notices that no road between city S and H.
A blank line is followed after each test case.
Output
For each test case, output a single integer in a separate line, indicating the minimum number of people the police used.
Sample Input
15 5 1 51 6 6 11 11 21 32 43 44 5
Sample Output
11
#include<cstdio>#include<cstring>#include<queue>#include<algorithm>using namespace std;#define MAXN 1010#define MAXM 1000000#define INF 0x3f3f3f3fint dis[MAXN],vis[MAXN],map[MAXN][MAXN],cur[MAXN];int n,S,H,m,cnt,head[MAXN];struct node{int u,v,cap,flow,next;}edge[MAXM];void add(int a,int b,int c){node E={a,b,c,0,head[a]};edge[cnt]=E;head[a]=cnt++;node E1={b,a,0,0,head[b]};edge[cnt]=E1;head[b]=cnt++;}void getmap(){cnt=0;memset(head,-1,sizeof(head));scanf("%d%d%d%d",&n,&m,&S,&H);for(int i=1;i<=n;i++){int a;scanf("%d",&a);if(i==S||i==H)add(i,i+n,INF);elseadd(i,i+n,a);}for(int i=0;i<m;i++){int a,b;scanf("%d%d",&a,&b);add(a+n,b,INF);add(b+n,a,INF);}}bool BFS(int s,int t){memset(dis,-1,sizeof(dis));memset(vis,0,sizeof(vis));queue<int>q;q.push(s);vis[s]=1;dis[s]=0;while(!q.empty()){int u=q.front();q.pop();for(int i=head[u];i!=-1;i=edge[i].next){node E=edge[i];if(!vis[E.v]&&E.cap>E.flow){dis[E.v]=dis[E.u]+1;vis[E.v]=1;if(E.v==t) return true;q.push(E.v);}}}return false;}int DFS(int x,int a,int e){if(a==0||x==e) return a;int flow=0,f;for(int &i=cur[x];i!=-1;i=edge[i].next){node &E=edge[i];if(dis[x]+1==dis[E.v]&&(f=DFS(E.v,min(E.cap-E.flow,a),e))>0){a-=f;flow+=f;edge[i].flow+=f;edge[i^1].flow-=f;if(a==0) break;}}return flow;}int MAXflow(int s,int t){int flow=0;while(BFS(s,t)){memcpy(cur,head,sizeof(head));flow+=DFS(s,INF,t);}return flow;}int main(){int t;scanf("%d",&t);while(t--){getmap();printf("%d\n",MAXflow(S,H+n));}return 0;}
0 0
- hdoj 3491 Thieves 【最小割点集】
- hdoj--3491--Thieves(最小割点集)
- hdoj 3491 Thieves 【最小割 + 拆点】
- HDOJ 3491 - Thieves 裸无向图的最小点权割...
- 【网络流】 HDOJ 3491 Thieves
- hdu 3491 Thieves(最小割拆点)
- HDU 3491 Thieves | 最小割
- 【HDU】3491 Thieves 最小点割集
- hdu 3491 Thieves 最小割
- hdu 3491 Thieves(最小割)
- HDU 3491 Thieves 拆点 最小割
- Thieves (hdu 3491 拆点 最小割)
- Thieves----简单最小割
- hdu 3491 Thieves
- hdu 3491 Thieves
- hdu 3491 Thieves
- HDU-3491 Thieves
- HDU 3491 Thieves 最小点割集+拆点==最大流(建图可贵)
- 保护古文化遗产海报
- SQLSERVER2008服务无法启动
- Android——Matrix变换矩阵的探索(1)
- Android自定义View的一般步骤
- Android BroastCast的使用详解
- hdoj--3491--Thieves(最小割点集)
- Jboss5.1类加载及配置文件读取解密
- UESTC - 1045 Lovely princess (模拟)水
- 智能指针使用介绍
- 第十周周赛——周赛兼组队赛第二场题解(出自 BNUOJ28207,BNUOJ28201,BNUOJ28209,codeforces 667B,HDU 5439,HDU 5478)
- 实战案例:一台主机不能设置两个网关
- 剑指Offer-调整数组奇数位于偶数前面
- C++输入和输出流
- CudaDeviceSynchronize vs cudaThreadSynchronize vs cudaStreamSynchronize