liuyifan @ 2019-05-03 16:34:48
RT.
#include<bits/stdc++.h>
#define reg register
#define ll long long
#define inf 0x3f3f3f3f
using namespace std;
struct edge
{
int from,to,x,flow,pre;
}e[1000005];
queue<int>q;
int m,n,h[1000005],tot,pre[1000005],a[1000005],flow,s,t,x,y,z;
inline void clear(queue<int>&q)
{
queue<int>x;
swap(x,q);
}
inline void addedge(int from,int to,int x)
{
tot++;
e[tot].from=from;
e[tot].to=to;
e[tot].x=x;
e[tot].flow=0;
e[tot].pre=h[from];
h[from]=tot;
}
int main()
{
scanf("%d%d%d%d",&m,&n,&s,&t);
for(reg int i=1;i<=n;i++)
{
scanf("%d%d%d",&x,&y,&z);
addedge(x,y,z);
addedge(y,x,0);
}
while(1)
{
memset(a,0,sizeof(a));
clear(q);
q.push(s);
a[s]=inf;
pre[s]=0;
while(!q.empty())
{
reg int u=q.front();
q.pop();
for(int i=h[u];i;i=e[i].pre)
{
reg int v=e[i].to;
if(!a[v]&&e[i].x>e[i].flow)
{
a[v]=min(a[u],e[i].x-e[i].flow);
pre[v]=i;
q.push(v);
}
}
if(a[t])break;
}
if(!a[t])break;
for(int u=t;u!=s;u=e[pre[u]].from)
{
e[pre[u]].flow+=a[t];
e[(pre[u]-1)^1+1].flow-=a[t];
}
flow+=a[t];
}
printf("%d",flow);
return 0;
}
附赠第3个点(被卡掉的点)数据: input:
10 25 2 10
3 4 4
4 3 45
3 5 80
1 6 94
3 7 63
9 8 92
1 9 75
6 3 12
7 9 63
6 1 39
6 1 97
9 7 33
7 4 55
8 9 36
5 2 61
9 8 97
2 4 36
1 2 2
10 2 14
5 9 82
5 1 32
6 2 94
9 2 10
6 10 50
7 6 53
output:
36
by qsmoonzh @ 2019-05-03 16:37:51
头像好评
by iotang @ 2019-05-03 16:42:54
来写 isap 啊
by liuyifan @ 2019-05-03 16:44:57
@iotang 我是WA不是TLE emmmm
by wubaiting2020 @ 2019-05-03 16:56:26
头像好评
by Soledad_S @ 2019-05-03 16:57:32
头像好评
by c2020HXW @ 2019-05-03 16:58:00
头像好评