Thieves HDU
来源:互联网 发布:音轨合成软件下载 编辑:程序博客网 时间:2024/05/22 16:55
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?
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.
Output
For each test case, output a single integer in a separate line, indicating the minimum number of people the police used.
Sample Input
1
5 5 1 5
1 6 6 11 1
1 2
1 3
2 4
3 4
4 5
Sample Output
11
这次就是点割集了,当然点是带权的,不仅是这种类型的题目,还有就是什么不重复经过点(另一种是不重复经过边),就需要对点考虑的问题,一般讨论就是还是转换成对边的处理,就把点拆成两个点,这两点连边,然后用这条边来代表这个点,仅此而已。至此点集问题和边集问题就统一了(有一点我们要知道,我们对点是不好处理的,最终都是要转化成对边的处理)
#include<iostream>#include<cstdio>#include<cmath>#include<cstring>#include<queue>#define INF 0x3f3f3f3fusing namespace std;const int maxn=205;const int maxx=40205;int edge;int to[maxx],flow[maxx],nex[maxx];int head[maxn];void addEdge(int v,int u,int cap){ to[edge]=u,flow[edge]=cap,nex[edge]=head[v],head[v]=edge++; to[edge]=v,flow[edge]=0,nex[edge]=head[u],head[u]=edge++;}int vis[maxn];int pre[maxn];bool bfs(int s,int e){ queue<int> que; pre[s]=-1; memset(vis,-1,sizeof(vis)); que.push(s); vis[s]=0; while(!que.empty()) { int u=que.front(); que.pop(); for(int i=head[u];~i;i=nex[i]) { int v=to[i]; if(vis[v]==-1&&flow[i]) { vis[v]=vis[u]+1; if(v==e) return true; que.push(v); } } } return false;}int dfs(int s,int t,int f){ if(s==t||!f) return f; int r=0; for(int i=head[s];~i;i=nex[i]) { int v=to[i]; if(vis[v]==vis[s]+1&&flow[i]) { int d=dfs(v,t,min(f,flow[i])); if(d>0) { flow[i]-=d; flow[i^1]+=d; r+=d; f-=d; if(!f) break; } } } if(!r) vis[s]=INF; return r;}int maxFlow(int s ,int e)//然后直接调用这个即可{ int ans=0; while(bfs(s,e)) ans+=dfs(s,e,INF); return ans;}void init()//记得每次使用前初始化{ memset(head,-1,sizeof(head)); edge=0;}int main(){ int t; int x,y; int n,m; int s,h; scanf("%d",&t); while(t--) { init(); scanf("%d%d%d%d",&n,&m,&s,&h); addEdge(s,n+s,INF); addEdge(h,n+h,INF); addEdge(0,s,INF); addEdge(n+h,n+n+1,INF); for(int i=1;i<=n;i++) { scanf("%d",&x); if(i==s||i==h) continue; addEdge(i,n+i,x); } while(m--) { scanf("%d%d",&x,&y); addEdge(x+n,y,INF); addEdge(n+y,x,INF); } int ans=maxFlow(0,n+n+1); printf("%d\n",ans); } return 0;}
- Thieves HDU
- hdu 3491 Thieves
- hdu 3491 Thieves
- hdu 3491 Thieves
- HDU-3491 Thieves
- hdu 3491 Thieves(最小割拆点)
- HDU 3491 Thieves | 最小割
- 【HDU】3491 Thieves 最小点割集
- hdu 3491 Thieves 最小割
- HDU 3491 Thieves 【拆点+最大流】
- hdu 3491 Thieves(最小割)
- HDU 3491 Thieves 拆点 最小割
- Thieves (hdu 3491 拆点 最小割)
- HDU 3491 Thieves(经典拆点建图,割点)
- HDU 3491 Thieves 最小点割集+拆点==最大流(建图可贵)
- hdu 3491 Thieves //2010 ACM-ICPC Multi-University Training Contest(6)——Host by BIT
- Den of thieves
- Den of thieves
- 维护集合Ⅱ【Splay】
- Sass
- Eclipse操作应用
- 在这里本蒟蒻推荐一个OJ
- logstash过滤器filter grok多种日志匹配使用心得
- Thieves HDU
- PB微信支付【刷卡支付】【扫码支付】【订单查询】
- Ajax如何传递多个参数
- 不用代码也能生成请求接口类
- webpack使用初体验(爽)
- 正则表达式贪婪模式,单词边界 ,多行模式,子表达式(java版)
- Mac下iTerm2光标按照单词快速移动设置
- java.lang.IllegalStateException: This app has been built with an incorrect configuration. Please co
- 洛谷 P2024 食物链