这种题目如果顶点或者边的数目开得少的话就会显示T,所以注意一下就好
#include <iostream>
#include <cstdio>
#include <cstring>
#include <queue>
#include <map>
#include <vector>
#include <string>
#define inf 0x3f3f3f3f
using namespace std;
int S,T;//源点和汇点
int N,F;
const int maxe=1e5+1000;
const int maxv=1100;
struct edge
{
int to,w,next;
}e[maxe<<1];
int head[maxv<<1],depth[maxv],cnt;
void init()
{
memset(head,-1,sizeof(head));
cnt=-1;
}
void add_edge(int u,int v,int w)
{
e[++cnt].to=v;
e[cnt].w=w;
e[cnt].next=head[u];
head[u]=cnt;
}
void _add(int u,int v,int w)
{
add_edge(u,v,w);
add_edge(v,u,0);
}
bool bfs()
{
queue<int> q;
while(!q.empty()) q.pop();
memset(depth,0,sizeof(depth));
depth[S]=1;
q.push(S);
while(!q.empty())
{
int u=q.front();q.pop();
for(int i=head[u];i!=-1;i=e[i].next)
{
if(!depth[e[i].to] && e[i].w>0)
{
depth[e[i].to]=depth[u]+1;
q.push(e[i].to);
}
}
}
if(!depth[T]) return false;
return true;
}
int dfs(int u,int flow)
{
if(u==T) return flow;
int ret=0;
for(int i=head[u];i!=-1 && flow;i=e[i].next)
{
if(depth[u]+1==depth[e[i].to] && e[i].w!=0)
{
int tmp=dfs(e[i].to,min(e[i].w,flow));
if(tmp>0)
{
flow-=tmp;
ret+=tmp;
e[i].w-=tmp;
e[i^1].w+=tmp;
}
}
}
return ret;
}
int Dinic()
{
int ans=0;
while(bfs())
{
ans+=dfs(S,inf);
}
return ans;
}
int main()
{
while(scanf("%d %d",&N,&F)!=EOF)
{
init();
scanf("%d %d",&S,&T);
T=T+300;
for(int i=1;i<=N;i++)
{
int temp;
scanf("%d",&temp);
_add(i,i+300,temp);
}
for(int i=1;i<=F;i++)
{
int x,y;
scanf("%d %d",&x,&y);
_add(x+300,y,inf);
_add(y+300,x,inf);
}
printf("%d\n",Dinic());
}
return 0;
}