题意:警察蜀黍知道有一伙犯罪团伙要从S点到达H点。每一个点需要一定的人数镇守。问需要最少的人数截断犯罪团伙从S到H的路使得不能从S到达H。

建图:
拆点。每个点i拆成i->i’和i’->i(因为是双向边),边权为需要的人数
存在一条u->v的边就这么建u’->v和v’->u(双向边),边权为INF。
代码:

//author: CHC
//First Edit Time: 2014-11-17 22:53
//Last Edit Time: 2014-11-17 23:26
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <set>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <algorithm>
#include <limits>
using namespace std;
typedef long long LL;
const int MAXN=1e+4;
const int MAXM=1e+5;
const int INF = numeric_limits<int>::max();
const LL LL_INF= numeric_limits<LL>::max();
struct Edge
{
int from,to,ci,next;
Edge(){}
Edge(int _from,int _to,int _ci,int _next):from(_from),to(_to),ci(_ci),next(_next){}
}e[MAXM];
int head[MAXN],tot;
int dis[MAXN];
int top,sta[MAXN],cur[MAXN];
inline void init(){
memset(head,-1,sizeof(head));
tot=0;
}
inline void AddEdge(int u,int v,int ci0,int ci1=0){
e[tot]=Edge(u,v,ci0,head[u]);
head[u]=tot++;
e[tot]=Edge(v,u,ci1,head[v]);
head[v]=tot++;
}
inline bool bfs(int st,int et){
memset(dis,0,sizeof(dis));
dis[st]=1;
queue <int> q;
q.push(st);
while(!q.empty()){
int now=q.front();
q.pop();
for(int i=head[now];i!=-1;i=e[i].next){
int next=e[i].to;
if(e[i].ci&&!dis[next]){
dis[next]=dis[now]+1;
if(next==et)return true;
q.push(next);
}
}
}
return false;
}
LL Dinic(int st,int et){
LL ans=0;
while(bfs(st,et)){
//printf("here\n");
top=0;
memcpy(cur,head,sizeof(head));
int u=st,i;
while(1){
if(u==et){
int pos,minn=INF;
//printf("top:%d\n",top);
for(i=0;i<top;i++)
{
if(minn>e[sta[i]].ci){
minn=e[sta[i]].ci;
pos=i;
}
//printf("%d --> %d\n",e[sta[i]].from,e[sta[i]].to);
}
for(i=0;i<top;i++){
e[sta[i]].ci-=minn;
e[sta[i]^1].ci+=minn;
}
top=pos;
u=e[sta[top]].from;
ans+=minn;
//printf("minn:%d\n\n",minn);
}
for(i=cur[u];i!=-1;cur[u]=i=e[i].next)
if(e[i].ci&&dis[u]+1==dis[e[i].to])break;
if(cur[u]!=-1){
sta[top++]=cur[u];
u=e[cur[u]].to;
}
else {
if(top==0)break;
dis[u]=0;
u=e[sta[--top]].from;
}
}
}
return ans;
}
int cs[MAXN];
int main()
{
int t,n,m,s,h;
scanf("%d",&t);
while(t--){
scanf("%d%d%d%d",&n,&m,&s,&h);
init();
for(int i=1,x;i<=n;i++){
scanf("%d",&x);
//i-->i'
AddEdge((i<<1),(i<<1)|1,x);
AddEdge((i<<1)|1,(i<<1),x);
}
for(int i=0,x,y;i<m;i++){
scanf("%d%d",&x,&y);
AddEdge((x<<1)|1,(y<<1),100000);
AddEdge((y<<1)|1,(x<<1),100000);
}
LL ans=Dinic((s<<1)|1,(h<<1));
printf("%I64d\n",ans);
}
scanf(" ");
return 0;
}