1163: [Baltic2008]Mafia
Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 263 Solved: 167
[Submit][Status][Discuss]
Description
匪徒准备从一个车站转移毒品到另一个车站,警方准备进行布控. 对于每个车站进行布控都需要一定的代价,现在警方希望使用最小的代价控制一些车站,使得去掉这些车站后,匪徒无法从原定的初始点到达目标点
Input
第一行输入N,M代表车站的总个数,及有多少条双向边连接它们. 2<=n<=200 , 1 <=m<=20000. 第二行给出两个数a,b,代表匪徒的出发点及目标点.1<=a,b<=N,a<>b. 再下来有N行,给出对第i个车站进行布控所需要的Money,其不超过10 000 000 再下来M行,用于描述图的结构.
Output
最少需要多少Money
Sample Input
5 6
5 3
2
4
8
3
10
1 5
1 2
2 4
4 5
2 3
3 4
5 3
2
4
8
3
10
1 5
1 2
2 4
4 5
2 3
3 4
Sample Output
5
直接拆点最小割
空间开小 RE一发
#include<cmath>
#include<ctime>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<complex>
#include<iostream>
#include<algorithm>
#include<iomanip>
#include<vector>
#include<string>
#include<bitset>
#include<queue>
#include<map>
#include<set>
using namespace std;
typedef long long ll;
inline int read()
{
int x=0,f=1;char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){x=(x<<1)+(x<<3)+ch-'0';ch=getchar();}
return x*f;
}
void print(int x)
{if(x<0)putchar('-'),x=-x;if(x>=10)print(x/10);putchar(x%10+'0');}
const int N=5000,M=501000,inf=0X3f3f3f3f;
int ecnt=1,last[N];
struct EDGE{int to,nt,val;}e[M];
inline void readd(int u,int v,int val)
{e[++ecnt]=(EDGE){v,last[u],val};last[u]=ecnt;}
inline void add(int u,int v,int val)
{readd(u,v,val);readd(v,u,0);}
int d[N],q[N],S=0,T=N-1;
bool bfs()
{
memset(d,0,sizeof(d));d[S]=1;
register int head=0,tail=1,u,i;
while(head<tail)
{
u=q[head++];
for(i=last[u];i;i=e[i].nt)if(!d[e[i].to]&&e[i].val)
{d[e[i].to]=d[u]+1;q[tail++]=e[i].to;}
}//cout<<endl;
return d[T];
}
int dfs(int u,int lim)
{
if(T==u||!lim)return lim;
register int res=0,i,tmp;
for(i=last[u];i;i=e[i].nt)
if(d[e[i].to]==d[u]+1&&e[i].val)
{
tmp=dfs(e[i].to,min(e[i].val,lim));
lim-=tmp;res+=tmp;e[i].val-=tmp;e[i^1].val+=tmp;
if(!lim)break;
}
if(!res)d[u]=-1;return res;
}
int ans=0;
void dinic()
{while(bfs())ans+=dfs(S,inf);}
int main()
{
int n=read(),m=read(),a=read(),b=read();
register int i,u,v;
for(i=1;i<=n;++i)u=read(),add(i,i+n,u);
for(i=1;i<=m;++i)
{
u=read();v=read();
add(v+n,u,inf);add(u+n,v,inf);
}
add(S,a,inf);add(b+n,T,inf);
dinic();
print(ans);puts("");return 0;
}
/*
5 6
5 3
2
4
8
3
10
1 5
1 2
2 4
4 5
2 3
3 4
5
*/